Repository navigation
feat(app): copy file paths from the file tree context menu - #799
Conversation
|
@leemour is attempting to deploy a commit to the murongg's projects Team on Vercel. A member of the Team first needs to authorize it. |
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 <noreply@anthropic.com>
ab4f746 to
f371f14
Compare
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 <noreply@anthropic.com>
murongg
left a comment
There was a problem hiding this comment.
Please derive tab-relative paths from the effective workspace directory and surface clipboard failures in both menus. The three focused suites passed all 155 existing tests. A focused tab reproduction with the standalone-file source path fails because the relative-path action is missing.
| onRevealTabInFileTree={handleRevealPathInFileTree} | ||
| onRenameTab={handleRenameTitlebarTab} | ||
| onSelectTab={handleSelectTitlebarTab} | ||
| rootPath={fileTree.sourcePath} |
There was a problem hiding this comment.
[P2] Use the directory that the file tree actually shows. Opening a Markdown file directly calls setRootFromMarkdownFilePath, which stores the file's path as fileTree.sourcePath. For /synthetic/docs/alpha.md, the sidebar shows /synthetic/docs, but the tab receives /synthetic/docs/alpha.md as rootPath. The tab omits Copy relative path for alpha.md, and siblings won't match this prefix either. Please pass the resolved workspace directory and add a regression test for opening a standalone file.
There was a problem hiding this comment.
| name: template.name | ||
| })) | ||
| : undefined, | ||
| copyPath: (path) => navigator.clipboard?.writeText(path).catch(() => {}), |
There was a problem hiding this comment.
[P3] Surface clipboard write failures. With writeText rejecting with NotAllowedError, I confirmed in Chromium that Copy relative path stays enabled and closes the menu without copying or showing a message. The tab menu now has the same empty catch. Please use the same failure handling for both menus and test denied clipboard writes.
There was a problem hiding this comment.
Fixed in 2ad454a. Both menus now share one helper that shows an error toast when the clipboard is missing or rejects. Added tests for a denied write in the file tree menu and in the tab menu
… failures Review follow-up for the copy path actions. Opening a Markdown file directly stores the file itself as the file tree source path, while the sidebar shows its parent folder. The tab menu used the source path as its root, so "Copy relative path" was missing for that file and its siblings. The file tree hook now exposes workspacePath, the directory the tree actually shows, and the tab bar uses it. Both menus swallowed clipboard errors, so a denied write closed the menu without copying or telling the user. They now share copyPathToClipboard, which shows an error toast when the clipboard is missing or rejects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening a Markdown file directly makes the file itself the tree source path. Check that its tab still offers Copy relative path, which needs the folder the file tree shows rather than the source path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Adds Copy path and Copy relative path to the file tree context menu for files and folders, like VS Code's explorer, and to the document tab context menu.
Changes
packages/app/src/runtime/context-menu-items.ts: two new entries after "Open containing folder", for files and folders. Both call a newcopyPathhandler. "Copy path" appears only when the path is a real file system path (POSIX, Windows drive or UNC). Both are disabled for a multi-selection.packages/app/src/lib/tauri/menu.ts: thecopyPathhandler type.packages/app/src/components/MarkdownFileTreeDrawer.tsx: the handler writes withnavigator.clipboard.writeText, the same waySettingsWindowandAiAgentPanelcopy text. The context menu is drawn in the page on both desktop and web, so the click counts as a user gesture.packages/app/src/components/MarkdownTabsBar.tsx,App.tsx: the same two items in the tab context menu. A tab only knows its absolute path, so the relative path is computed from the file tree root (newrootPathprop). It's offered only when the file is inside that folder.packages/shared/src/i18n/locales/*: labels in all 11 locales.Desktop and web
/home/me/notes/docs/guide.mddocs/guide.mdweb-folder://…handlesdocs/guide.mdVerification
pnpm --filter @markra/shared testpassed, 64 testspnpm --filter @markra/app typecheck:testpassedpnpm --filter @markra/app testpassed, 141 files and 1672 testspnpm --filter @markra/app buildandpnpm --filter @markra/web buildpassedKnown limitations
I worked on this together with Claude Code.
🤖 Generated with Claude Code