Skip to content

feat(app): copy file paths from the file tree context menu - #799

Merged
murongg merged 4 commits into
markrahq:v2from
leemour:feat/file-tree-copy-path
Nov 25, 2026
Merged

murongg merged 4 commits into
markrahq:v2from
leemour:feat/file-tree-copy-path

Conversation

@leemour

@leemour leemour commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 new copyPath handler. "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: the copyPath handler type.
  • packages/app/src/components/MarkdownFileTreeDrawer.tsx: the handler writes with navigator.clipboard.writeText, the same way SettingsWindow and AiAgentPanel copy 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 (new rootPath prop). It's offered only when the file is inside that folder.
  • packages/shared/src/i18n/locales/*: labels in all 11 locales.
  • Tests: menu entries (absolute and relative path, file and folder, web-style path, multi-selection), the drawer writing to the clipboard, and the tab menu (inside and outside the open folder).

Desktop and web

Copy path Copy relative path
Desktop Absolute path, e.g. /home/me/notes/docs/guide.md docs/guide.md
Web Hidden: paths are internal web-folder://… handles docs/guide.md

Verification

  • pnpm --filter @markra/shared test passed, 64 tests
  • pnpm --filter @markra/app typecheck:test passed
  • pnpm --filter @markra/app test passed, 141 files and 1672 tests
  • pnpm --filter @markra/app build and pnpm --filter @markra/web build passed

Known limitations

  • With several files selected, both items are disabled. VS Code copies all selected paths, one per line. I can add that if you want it.
  • No screenshot yet. I'll add one from a Linux desktop build.

I worked on this together with Claude Code.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@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.

@leemour
leemour marked this pull request as draft November 24, 2026 00:41
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>
@leemour
leemour force-pushed the feat/file-tree-copy-path branch from ab4f746 to f371f14 Compare November 24, 2026 01:01
@leemour
leemour changed the base branch from main to v2 November 24, 2026 01:01
@leemour
leemour marked this pull request as ready for review November 24, 2026 01:01
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 murongg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/app/src/App.tsx Outdated
onRevealTabInFileTree={handleRevealPathInFileTree}
onRenameTab={handleRenameTitlebarTab}
onSelectTab={handleSelectTitlebarTab}
rootPath={fileTree.sourcePath}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the tab got the file itself as the root. Fixed in 2ad454a - the file tree hook now exposes the folder the sidebar shows and the tab bar uses it. cc774df adds an App test that opens a standalone file and checks Copy relative path on its tab, it fails on the old wiring

name: template.name
}))
: undefined,
copyPath: (path) => navigator.clipboard?.writeText(path).catch(() => {}),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

leemour and others added 2 commits November 24, 2026 15:14
… 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>
@murongg
murongg merged commit 4feeccb into markrahq:v2 Nov 25, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants