From f371f14491cdccf62221f0c8ab8b73f28d1ea692 Mon Sep 17 00:00:00 2001 From: leemour Date: Tue, 24 Nov 2026 01:40:07 +0100 Subject: [PATCH 1/4] feat(app): copy file paths from the file tree context menu Add "Copy path" and "Copy relative path" to the file tree context menu for files and folders, like VS Code's explorer. - "Copy path" copies the absolute file system path. It is shown only when the path is a real one (POSIX, Windows drive or UNC), so the web build, whose paths are internal web-folder:// handles, offers only "Copy relative path". - "Copy relative path" copies the path relative to the opened folder. - Both are disabled for a multi-selection. The menu is drawn in the page on desktop and web, so the click is a user gesture and navigator.clipboard.writeText works, as it already does in the settings window and the AI agent panel. Co-Authored-By: Claude Opus 5.5 --- .../MarkdownFileTreeDrawer.test.tsx | 30 +++++++++++++++++ .../src/components/MarkdownFileTreeDrawer.tsx | 1 + packages/app/src/lib/tauri/menu.ts | 1 + .../src/runtime/context-menu-items.test.ts | 32 +++++++++++++++++++ .../app/src/runtime/context-menu-items.ts | 27 ++++++++++++++++ packages/shared/src/i18n/locales/de.ts | 2 ++ packages/shared/src/i18n/locales/en.ts | 2 ++ packages/shared/src/i18n/locales/es.ts | 2 ++ packages/shared/src/i18n/locales/fr.ts | 2 ++ packages/shared/src/i18n/locales/it.ts | 2 ++ packages/shared/src/i18n/locales/ja.ts | 2 ++ packages/shared/src/i18n/locales/ko.ts | 2 ++ packages/shared/src/i18n/locales/pt-BR.ts | 2 ++ packages/shared/src/i18n/locales/ru.ts | 2 ++ packages/shared/src/i18n/locales/types.ts | 2 ++ packages/shared/src/i18n/locales/zh-CN.ts | 2 ++ packages/shared/src/i18n/locales/zh-TW.ts | 2 ++ 17 files changed, 115 insertions(+) diff --git a/packages/app/src/components/MarkdownFileTreeDrawer.test.tsx b/packages/app/src/components/MarkdownFileTreeDrawer.test.tsx index 9fbef7345..ff969985c 100644 --- a/packages/app/src/components/MarkdownFileTreeDrawer.test.tsx +++ b/packages/app/src/components/MarkdownFileTreeDrawer.test.tsx @@ -2718,6 +2718,36 @@ describe("MarkdownFileTreeDrawer", () => { expect(openContainingFolder).toHaveBeenCalledWith("/vault"); }); + it("copies a file path from file tree context menus", async () => { + const writeText = vi.fn().mockResolvedValue(undefined); + vi.stubGlobal("navigator", { ...navigator, clipboard: { writeText } }); + + try { + render( + {}} + onSelectOutlineItem={() => {}} + /> + ); + + fireEvent.contextMenu(screen.getByRole("button", { name: "Untitled.md" })); + const fileContextHandlers = mockedShowNativeMarkdownFileTreeContextMenu.mock.calls[0]?.[0]; + await act(async () => { + await fileContextHandlers?.copyPath?.("/vault/Untitled.md"); + }); + + expect(writeText).toHaveBeenCalledWith("/vault/Untitled.md"); + } finally { + vi.unstubAllGlobals(); + } + }); + it("shows text editing actions when right-clicking a file name input", async () => { const createFile = vi.fn(); mockedReadNativeClipboardText.mockResolvedValue("Pasted note"); diff --git a/packages/app/src/components/MarkdownFileTreeDrawer.tsx b/packages/app/src/components/MarkdownFileTreeDrawer.tsx index 01d8787ee..e349c4d22 100644 --- a/packages/app/src/components/MarkdownFileTreeDrawer.tsx +++ b/packages/app/src/components/MarkdownFileTreeDrawer.tsx @@ -1602,6 +1602,7 @@ export function MarkdownFileTreeDrawer({ name: template.name })) : undefined, + copyPath: (path) => navigator.clipboard?.writeText(path).catch(() => {}), createFolder: folderCreationAvailable ? () => startCreatingFolder(createTargetFolderPath) : undefined, deleteFile: deleteFileTreeTarget, openContainingFolder: onOpenContainingFolder diff --git a/packages/app/src/lib/tauri/menu.ts b/packages/app/src/lib/tauri/menu.ts index 87c061be3..ae2bed49c 100644 --- a/packages/app/src/lib/tauri/menu.ts +++ b/packages/app/src/lib/tauri/menu.ts @@ -17,6 +17,7 @@ export type NativeMarkdownFileTreeContextMenuHandlers = { id: string; name: string; }>; + copyPath?: (path: string) => unknown | Promise; createFolder?: () => unknown | Promise; deleteFile?: (file: NativeMarkdownFolderFile) => unknown | Promise; openContainingFolder?: (file?: NativeMarkdownFolderFile) => unknown | Promise; diff --git a/packages/app/src/runtime/context-menu-items.test.ts b/packages/app/src/runtime/context-menu-items.test.ts index 67a75a9d2..e78d52856 100644 --- a/packages/app/src/runtime/context-menu-items.test.ts +++ b/packages/app/src/runtime/context-menu-items.test.ts @@ -463,4 +463,36 @@ describe("markdown file tree context menu entries", () => { expect(menuItemById(entries, "markra:file-tree:open-containing-folder").disabled).toBe(true); expect(menuItemById(entries, "markra:file-tree:rename").disabled).toBe(true); }); + + it("copies the absolute and relative path of a file or folder", () => { + const copyPath = vi.fn(); + const file = { name: "guide.md", path: "/mock-project/docs/guide.md", relativePath: "docs/guide.md" }; + const folder = { kind: "folder" as const, name: "docs", path: "C:\\mock-project\\docs", relativePath: "docs" }; + + menuItemById(createMarkdownFileTreeContextMenuEntries({ copyPath }, "en", file), "markra:file-tree:copy-path").onSelect?.(); + menuItemById( + createMarkdownFileTreeContextMenuEntries({ copyPath }, "en", file), + "markra:file-tree:copy-relative-path" + ).onSelect?.(); + menuItemById(createMarkdownFileTreeContextMenuEntries({ copyPath }, "en", folder), "markra:file-tree:copy-path").onSelect?.(); + + expect(copyPath.mock.calls).toEqual([["/mock-project/docs/guide.md"], ["docs/guide.md"], ["C:\\mock-project\\docs"]]); + }); + + it("offers only the relative path when the file has no file system path", () => { + const file = { name: "guide.md", path: "web-folder://mock-handle/docs/guide.md", relativePath: "docs/guide.md" }; + const ids = createMarkdownFileTreeContextMenuEntries({ copyPath: vi.fn() }, "en", file) + .flatMap((entry) => ("id" in entry ? [entry.id] : [])); + + expect(ids).toContain("markra:file-tree:copy-relative-path"); + expect(ids).not.toContain("markra:file-tree:copy-path"); + }); + + it("disables copying paths for a multi-selection", () => { + const file = { name: "guide.md", path: "/mock-project/docs/guide.md", relativePath: "docs/guide.md" }; + const entries = createMarkdownFileTreeContextMenuEntries({ copyPath: vi.fn(), multiSelect: true }, "en", file); + + expect(menuItemById(entries, "markra:file-tree:copy-path").disabled).toBe(true); + expect(menuItemById(entries, "markra:file-tree:copy-relative-path").disabled).toBe(true); + }); }); diff --git a/packages/app/src/runtime/context-menu-items.ts b/packages/app/src/runtime/context-menu-items.ts index 4fa3bab24..33a42cd8d 100644 --- a/packages/app/src/runtime/context-menu-items.ts +++ b/packages/app/src/runtime/context-menu-items.ts @@ -453,6 +453,31 @@ export function createEditorContextMenuEntriesFromOptions( ); } +const absoluteFilePathPattern = /^(?:\/|[A-Za-z]:[\\/]|\\\\)/u; + +function copyPathEntries( + handlers: NativeMarkdownFileTreeContextMenuHandlers, + file: NativeMarkdownFolderFile, + fileTreeId: (suffix: string) => string, + label: (key: I18nKey) => string +): ContextMenuEntry[] { + const { copyPath, multiSelect } = handlers; + if (!copyPath) return []; + + return [ + ...(absoluteFilePathPattern.test(file.path) + ? [contextMenuItem(fileTreeId("copy-path"), label("app.copyPath"), undefined, () => copyPath(file.path), multiSelect)] + : []), + contextMenuItem( + fileTreeId("copy-relative-path"), + label("app.copyRelativePath"), + undefined, + () => copyPath(file.relativePath), + multiSelect + ) + ]; +} + export function createMarkdownFileTreeContextMenuEntries( handlers: NativeMarkdownFileTreeContextMenuHandlers, language: AppLanguage = "en", @@ -495,6 +520,7 @@ export function createMarkdownFileTreeContextMenuEntries( entries.push( contextMenuSeparator(), contextMenuItem(fileTreeId("open-containing-folder"), label("app.openContainingFolder"), undefined, () => handlers.openContainingFolder?.(file), !handlers.openContainingFolder), + ...copyPathEntries(handlers, file, fileTreeId, label), contextMenuItem(fileTreeId("rename"), label("app.renameMarkdownFolder"), undefined, () => handlers.renameFile?.(file), !handlers.renameFile), contextMenuItem(fileTreeId("delete"), label("app.deleteMarkdownFolder"), undefined, () => handlers.deleteFile?.(file), !handlers.deleteFile) ); @@ -529,6 +555,7 @@ export function createMarkdownFileTreeContextMenuEntries( } entries.push( contextMenuItem(fileTreeId("open-containing-folder"), label("app.openContainingFolder"), undefined, () => handlers.openContainingFolder?.(file), multiSelect || !handlers.openContainingFolder), + ...copyPathEntries(handlers, file, fileTreeId, label), contextMenuItem(fileTreeId("rename"), label("app.renameMarkdownFile"), undefined, () => handlers.renameFile?.(file), multiSelect || !handlers.renameFile), contextMenuItem(fileTreeId("delete"), label("app.deleteMarkdownFile"), undefined, () => handlers.deleteFile?.(file), !handlers.deleteFile) ); diff --git a/packages/shared/src/i18n/locales/de.ts b/packages/shared/src/i18n/locales/de.ts index a0c251258..c3b3e84d4 100644 --- a/packages/shared/src/i18n/locales/de.ts +++ b/packages/shared/src/i18n/locales/de.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "Aus Vorlage erstellen", "app.saveMarkdownFileAsTemplate": "Als Vorlage speichern", "app.openContainingFolder": "Enthaltenden Ordner öffnen", + "app.copyPath": "Pfad kopieren", + "app.copyRelativePath": "Relativen Pfad kopieren", "app.markdownTemplateSaved": "Vorlage gespeichert.", "app.markdownTemplateSaveFailed": "Vorlage konnte nicht gespeichert werden.", "app.markdownFileSaveFailed": "Das Dokument konnte nicht gespeichert werden.", diff --git a/packages/shared/src/i18n/locales/en.ts b/packages/shared/src/i18n/locales/en.ts index 3283dabfa..93110cb20 100644 --- a/packages/shared/src/i18n/locales/en.ts +++ b/packages/shared/src/i18n/locales/en.ts @@ -750,6 +750,8 @@ const messages: BaseLocaleMessages = { "app.newMarkdownFileFromTemplate": "New from template", "app.saveMarkdownFileAsTemplate": "Save as template", "app.openContainingFolder": "Open containing folder", + "app.copyPath": "Copy path", + "app.copyRelativePath": "Copy relative path", "app.markdownTemplateSaved": "Template saved.", "app.markdownTemplateSaveFailed": "Could not save template.", "app.markdownFileSaveFailed": "Could not save the document.", diff --git a/packages/shared/src/i18n/locales/es.ts b/packages/shared/src/i18n/locales/es.ts index 97d18c5cf..a0556d966 100644 --- a/packages/shared/src/i18n/locales/es.ts +++ b/packages/shared/src/i18n/locales/es.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "Crear desde plantilla", "app.saveMarkdownFileAsTemplate": "Guardar como plantilla", "app.openContainingFolder": "Abrir carpeta contenedora", + "app.copyPath": "Copiar ruta", + "app.copyRelativePath": "Copiar ruta relativa", "app.markdownTemplateSaved": "Plantilla guardada.", "app.markdownTemplateSaveFailed": "No se pudo guardar la plantilla.", "app.markdownFileSaveFailed": "No se pudo guardar el documento.", diff --git a/packages/shared/src/i18n/locales/fr.ts b/packages/shared/src/i18n/locales/fr.ts index 9a5f8786c..48604bc52 100644 --- a/packages/shared/src/i18n/locales/fr.ts +++ b/packages/shared/src/i18n/locales/fr.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "Créer depuis un modèle", "app.saveMarkdownFileAsTemplate": "Enregistrer comme modèle", "app.openContainingFolder": "Ouvrir le dossier contenant", + "app.copyPath": "Copier le chemin", + "app.copyRelativePath": "Copier le chemin relatif", "app.markdownTemplateSaved": "Modèle enregistré.", "app.markdownTemplateSaveFailed": "Impossible d’enregistrer le modèle.", "app.markdownFileSaveFailed": "Impossible d’enregistrer le document.", diff --git a/packages/shared/src/i18n/locales/it.ts b/packages/shared/src/i18n/locales/it.ts index 42207e05f..0c68b9df4 100644 --- a/packages/shared/src/i18n/locales/it.ts +++ b/packages/shared/src/i18n/locales/it.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "Crea da modello", "app.saveMarkdownFileAsTemplate": "Salva come modello", "app.openContainingFolder": "Apri cartella contenitore", + "app.copyPath": "Copia percorso", + "app.copyRelativePath": "Copia percorso relativo", "app.markdownTemplateSaved": "Modello salvato.", "app.markdownTemplateSaveFailed": "Impossibile salvare il modello.", "app.markdownFileSaveFailed": "Impossibile salvare il documento.", diff --git a/packages/shared/src/i18n/locales/ja.ts b/packages/shared/src/i18n/locales/ja.ts index 693ec704c..2d1151ec0 100644 --- a/packages/shared/src/i18n/locales/ja.ts +++ b/packages/shared/src/i18n/locales/ja.ts @@ -404,6 +404,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "テンプレートから作成", "app.saveMarkdownFileAsTemplate": "テンプレートとして保存", "app.openContainingFolder": "所在フォルダーを開く", + "app.copyPath": "パスをコピー", + "app.copyRelativePath": "相対パスをコピー", "app.markdownTemplateSaved": "テンプレートとして保存しました。", "app.markdownTemplateSaveFailed": "テンプレートを保存できませんでした。", "app.markdownFileSaveFailed": "ドキュメントを保存できませんでした。", diff --git a/packages/shared/src/i18n/locales/ko.ts b/packages/shared/src/i18n/locales/ko.ts index 53815f304..dd94792df 100644 --- a/packages/shared/src/i18n/locales/ko.ts +++ b/packages/shared/src/i18n/locales/ko.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "템플릿에서 만들기", "app.saveMarkdownFileAsTemplate": "템플릿으로 저장", "app.openContainingFolder": "포함된 폴더 열기", + "app.copyPath": "경로 복사", + "app.copyRelativePath": "상대 경로 복사", "app.markdownTemplateSaved": "템플릿으로 저장했습니다.", "app.markdownTemplateSaveFailed": "템플릿을 저장할 수 없습니다.", "app.markdownFileSaveFailed": "문서를 저장할 수 없습니다.", diff --git a/packages/shared/src/i18n/locales/pt-BR.ts b/packages/shared/src/i18n/locales/pt-BR.ts index 3873fbe4d..7ab0fded7 100644 --- a/packages/shared/src/i18n/locales/pt-BR.ts +++ b/packages/shared/src/i18n/locales/pt-BR.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "Criar a partir de modelo", "app.saveMarkdownFileAsTemplate": "Salvar como modelo", "app.openContainingFolder": "Abrir pasta que contém", + "app.copyPath": "Copiar caminho", + "app.copyRelativePath": "Copiar caminho relativo", "app.markdownTemplateSaved": "Modelo salvo.", "app.markdownTemplateSaveFailed": "Não foi possível salvar o modelo.", "app.markdownFileSaveFailed": "Não foi possível salvar o documento.", diff --git a/packages/shared/src/i18n/locales/ru.ts b/packages/shared/src/i18n/locales/ru.ts index bb188c61d..aa1175290 100644 --- a/packages/shared/src/i18n/locales/ru.ts +++ b/packages/shared/src/i18n/locales/ru.ts @@ -395,6 +395,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "Создать из шаблона", "app.saveMarkdownFileAsTemplate": "Сохранить как шаблон", "app.openContainingFolder": "Открыть содержащую папку", + "app.copyPath": "Копировать путь", + "app.copyRelativePath": "Копировать относительный путь", "app.markdownTemplateSaved": "Шаблон сохранён.", "app.markdownTemplateSaveFailed": "Не удалось сохранить шаблон.", "app.markdownFileSaveFailed": "Не удалось сохранить документ.", diff --git a/packages/shared/src/i18n/locales/types.ts b/packages/shared/src/i18n/locales/types.ts index 45cc4d337..601319b3f 100644 --- a/packages/shared/src/i18n/locales/types.ts +++ b/packages/shared/src/i18n/locales/types.ts @@ -761,6 +761,8 @@ export type I18nKey = | "app.newMarkdownFileFromTemplate" | "app.saveMarkdownFileAsTemplate" | "app.openContainingFolder" + | "app.copyPath" + | "app.copyRelativePath" | "app.markdownTemplateSaved" | "app.markdownTemplateSaveFailed" | "app.markdownFileSaveFailed" diff --git a/packages/shared/src/i18n/locales/zh-CN.ts b/packages/shared/src/i18n/locales/zh-CN.ts index 57c64c08f..f2f408153 100644 --- a/packages/shared/src/i18n/locales/zh-CN.ts +++ b/packages/shared/src/i18n/locales/zh-CN.ts @@ -750,6 +750,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "从模板新建", "app.saveMarkdownFileAsTemplate": "保存为模板", "app.openContainingFolder": "打开所在文件夹", + "app.copyPath": "复制路径", + "app.copyRelativePath": "复制相对路径", "app.markdownTemplateSaved": "已保存为模板。", "app.markdownTemplateSaveFailed": "无法保存模板。", "app.markdownFileSaveFailed": "无法保存文档。", diff --git a/packages/shared/src/i18n/locales/zh-TW.ts b/packages/shared/src/i18n/locales/zh-TW.ts index e0554d4aa..1e8373859 100644 --- a/packages/shared/src/i18n/locales/zh-TW.ts +++ b/packages/shared/src/i18n/locales/zh-TW.ts @@ -404,6 +404,8 @@ const messages: LocaleMessages = { "app.newMarkdownFileFromTemplate": "從範本新增", "app.saveMarkdownFileAsTemplate": "儲存為範本", "app.openContainingFolder": "開啟所在資料夾", + "app.copyPath": "複製路徑", + "app.copyRelativePath": "複製相對路徑", "app.markdownTemplateSaved": "已儲存為範本。", "app.markdownTemplateSaveFailed": "無法儲存範本。", "app.markdownFileSaveFailed": "無法儲存文件。", From e25ae7dbc223d39d5579995a0e60d2d1e8a1c62e Mon Sep 17 00:00:00 2001 From: leemour Date: Tue, 24 Nov 2026 02:38:05 +0100 Subject: [PATCH 2/4] feat(app): copy file paths from the document tab context menu Right-clicking a document tab now offers "Copy path" and, when the file is inside the open folder, "Copy relative path", matching the file tree menu. Tabs only know the absolute path, so the relative path is computed from the file tree's root folder. Web tabs, whose paths are not file system paths, get neither item. Co-Authored-By: Claude Opus 5.5 --- packages/app/src/App.tsx | 1 + .../src/components/MarkdownTabsBar.test.tsx | 46 +++++++++++++++++ .../app/src/components/MarkdownTabsBar.tsx | 49 ++++++++++++++++++- .../app/src/runtime/context-menu-items.ts | 6 ++- 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 2c8e1a353..ee8db71e2 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -4552,6 +4552,7 @@ function WorkspaceApp() { onRevealTabInFileTree={handleRevealPathInFileTree} onRenameTab={handleRenameTitlebarTab} onSelectTab={handleSelectTitlebarTab} + rootPath={fileTree.sourcePath} /> ) : null; const appTitlebarActions = useMemo( diff --git a/packages/app/src/components/MarkdownTabsBar.test.tsx b/packages/app/src/components/MarkdownTabsBar.test.tsx index c2682f2a0..1ce516ac2 100644 --- a/packages/app/src/components/MarkdownTabsBar.test.tsx +++ b/packages/app/src/components/MarkdownTabsBar.test.tsx @@ -615,6 +615,52 @@ describe("MarkdownTabsBar", () => { expect(onCloseTab).toHaveBeenNthCalledWith(2, "tab-d"); }); + it("copies the tab file path and its path relative to the open folder", async () => { + const writeText = vi.fn().mockResolvedValue(undefined); + vi.stubGlobal("navigator", { ...navigator, clipboard: { writeText } }); + + try { + render( + {}} + onNewTab={() => {}} + onSelectTab={() => {}} + rootPath="/synthetic" + /> + ); + + fireEvent.contextMenu(screen.getByRole("tab", { name: /Alpha\.md/ })); + fireEvent.click(screen.getByRole("menuitem", { name: "Copy path" })); + fireEvent.contextMenu(screen.getByRole("tab", { name: /Alpha\.md/ })); + fireEvent.click(screen.getByRole("menuitem", { name: "Copy relative path" })); + + await waitFor(() => expect(writeText).toHaveBeenCalledTimes(2)); + expect(writeText.mock.calls).toEqual([["/synthetic/docs/alpha.md"], ["docs/alpha.md"]]); + } finally { + vi.unstubAllGlobals(); + } + }); + + it("offers no relative path for a tab outside the open folder", () => { + render( + {}} + onNewTab={() => {}} + onSelectTab={() => {}} + rootPath="/synthetic" + /> + ); + + fireEvent.contextMenu(screen.getByRole("tab", { name: /Alpha\.md/ })); + + expect(screen.getByRole("menuitem", { name: "Copy path" })).toBeInTheDocument(); + expect(screen.queryByRole("menuitem", { name: "Copy relative path" })).not.toBeInTheDocument(); + }); + it("opens tab actions from right click and closes related tabs", async () => { const onCloseTab = vi.fn(); diff --git a/packages/app/src/components/MarkdownTabsBar.tsx b/packages/app/src/components/MarkdownTabsBar.tsx index 0109c652e..f66f95b07 100644 --- a/packages/app/src/components/MarkdownTabsBar.tsx +++ b/packages/app/src/components/MarkdownTabsBar.tsx @@ -7,11 +7,12 @@ import { type PointerEvent as ReactPointerEvent, type WheelEvent as ReactWheelEvent } from "react"; -import { Columns2, FileText, ImageIcon, LocateFixed, Pencil, Plus, X } from "lucide-react"; +import { Columns2, Copy, FileText, ImageIcon, LocateFixed, Pencil, Plus, X } from "lucide-react"; import { IconButton, Tooltip } from "@markra/ui"; import { t, type AppLanguage } from "@markra/shared"; import type { MarkdownDocumentTab } from "../hooks/useMarkdownDocument"; import { ContextMenu, type ContextMenuEntry } from "./ContextMenu"; +import { isFileSystemPath } from "../runtime/context-menu-items"; export type MarkdownTabsBarDocumentItem = Pick & { displayKind?: "image" | "markdown"; @@ -33,6 +34,7 @@ type MarkdownTabsBarProps = { onNewTab: () => unknown; onOpenTabToSide?: (tabId: string, primaryTabId?: string) => unknown; onRevealTabInFileTree?: (path: string) => unknown; + rootPath?: string | null; onRenameTab?: (tab: MarkdownTabsBarDocumentItem, name: string) => unknown; onSelectTab: (tabId: string) => unknown; }; @@ -67,6 +69,47 @@ export const markdownTabDragDataType = "application/x-markra-document-tab"; const pointerTabDragThresholdPx = 6; const pointerTabDragPreviewOffsetPx = 12; +function pathRelativeToRoot(path: string, rootPath: string | null | undefined) { + const root = rootPath?.replace(/[\\/]+$/u, ""); + if (!root || !path.startsWith(root)) return null; + + const separator = path.charAt(root.length); + return separator === "/" || separator === "\\" ? path.slice(root.length + 1) : null; +} + +function copyPathEntries( + path: string, + rootPath: string | null | undefined, + label: (key: "app.copyPath" | "app.copyRelativePath") => string, + run: (action: () => unknown) => unknown +): ContextMenuEntry[] { + if (!isFileSystemPath(path)) return []; + + const copy = (text: string) => run(() => navigator.clipboard?.writeText(text).catch(() => {})); + const relativePath = pathRelativeToRoot(path, rootPath); + + return [ + { + icon: