Repository navigation
Conversation
…solute, Ctrl+Shift+R relative to its search folder Issue ARahim3#148 asked for a hotkey that puts the path of the selected search result on the clipboard as text, to paste into open/upload dialogs: the existing Ctrl+C copies the file itself (file-manager/chat paste), which does not paste into a dialog's name field, and the window's "Copy Path" menu line used `navigator.clipboard`, which needs Tauri's clipboard permission the shell's capability file doesn't carry — so it did nothing on Linux/Windows (and the panel had no path copy at all). The shell (Windows/Linux): a shared `copyPathText` in `results.js` takes Ctrl+Shift+C / Ctrl+Shift+R on a focused result in the panel and the window, and the window's right-click menu gains "Copy Relative Path" beside "Copy Path". The relative spelling comes from a Rust helper, `relative_path` (the longest containing search folder, `/` shown, case-insensitive like Windows spells folders; absolute when no root holds the file), exposed as `relative_path_text`. The text goes onto the system clipboard through a new `copy_text` command in `clipboard.rs` — CF_UNICODETEXT on Windows, GTK clipboard text on Linux, the native channel Ctrl+C's file copy already uses. The pre-push review rejected the original `navigator.clipboard.writeText` plan: Tauri serves its pages from a custom scheme (`http://tauri.localhost` on Windows), a non-secure context where the web clipboard API is unavailable — the native route needs no capability, no plugin, and no secure origin, and it is the mechanism this app has always pasted with. The panel's `panel-shown` event carries the shell's current folders, which the page keeps for the relative spelling (and the panel page gained its `state.info` — the review caught that the panel's state literal had none, so the first listener line threw on every show and the field lost focus: a visible panel breakage no suite at that commit exercised). Text selected in the query field or page keeps its own copy — Ctrl+Shift+C is WebKitGTK's copy-selection shortcut, and the guard lets it through. The Mac app mirrors it: ⌘⇧C / ⌘⇧R in the panel (SearchPanel key handling, same selected-text rule as ⌘C's), the panel key hints say "⌘⇧C Path", and the rows' menu gains "Copy Relative Path" — offered only where the folders are known (the panel threads them; the window rows don't today, and an item that would echo the absolute path under a relative label is a promise not to make). The spelling is one function, `FileDragView.relativeSpelling`, used by keys and menu alike; it trims trailing separators (any number) and treats a root spelled `/` as holding every absolute path, matching the shell's `relative_path` (the shell compares ASCII as Windows spells folder names, the Mac the whole alphabet — disclosed divergence for non-ASCII roots). Verified on this box: cargo test 14 green — `copy_path_tests` covers Windows backslashes, longest-folder nesting, case-insensitive roots, no-root and root-itself fallbacks, the `/` root (and the longest-folder rule beating it), and roots with one or many trailing separators; Swift suite 125 green (base count, app target compiles); shell JS `node --test` 17 pass, all pages pass `node --check`. Not verified: the clipboard writes in a live Tauri webview (the shell app doesn't run on macOS; the Windows `copy_text` block compiles only for Windows targets, disclosed), and the Mac panel keys (app GUI acceptance, morning). Disclosed edges: on Windows WebView2 Ctrl+Shift+C may be captured by the browser control for its own copy — the has-selection guard covers the common case; Ctrl+Shift+R is free. A Linux filename containing a literal `\` gets its separators rewritten in the relative spelling (both impls; near-unseen). Window-page folders refresh at window load (panel folders are fresh at every show) — a mid-session folder change on an open window spells new paths against the list the window was opened with until reload.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #148.
Problem
Users requested keyboard shortcuts to copy the selected search result's file path as plain text, making it possible to paste the path directly into an open or upload dialog.
The existing copy behavior did not support this workflow:
navigator.clipboard, which requires clipboard permissions that the shell's Tauri capability configuration does not provide. Consequently, it did not work on Linux or Windows.Changes
1. Windows and Linux Shell
A shared
copyPathTextimplementation inresults.jsadds two keyboard shortcuts for focused search results:Both the search panel and the main window support these shortcuts.
The main window's right-click context menu also gains a Copy Relative Path option alongside the existing Copy Path action.
2. Relative Path Resolution
Relative path generation is handled by a new Rust helper,
relative_path, exposed to the frontend throughrelative_path_text.The helper applies the following rules:
/as the path separator.This ensures nested search folders resolve against the most specific matching root.
3. Native System Clipboard Integration
A new Tauri command,
copy_text, handles copying path strings to the system clipboard.Platform-specific implementations use:
CF_UNICODETEXT.This uses the same native clipboard mechanism already used by the application's existing file-copy functionality.
Why Not
navigator.clipboard?The initial implementation used
navigator.clipboard.writeText, but pre-push code review identified a platform compatibility problem.Tauri serves its frontend through a custom URL scheme. On Windows, this uses
http://tauri.localhost, which is not considered a secure context for the browser clipboard API.Consequently, the web clipboard API is unavailable in this environment.
The native clipboard implementation avoids this limitation and does not require:
It also uses the same underlying native clipboard approach that the application already relies on.
4. Panel State and Selection Handling
Pre-push review also identified a regression in the original implementation.
The panel's
stateobject did not include aninfoproperty. As a result, its firstpanel-shownevent attempted to access missing state, causing an exception and preventing the search field from receiving focus.This is fixed by:
state.info.folders.The keyboard shortcuts also preserve normal text-selection behavior.
If text is selected in the search query field or elsewhere on the page, the shortcut is allowed to perform its normal copy-selection action instead of copying the selected file path.
This is particularly important for Ctrl+Shift+C, which WebKitGTK uses as a text-selection copy shortcut.
5. macOS Support
The macOS application receives equivalent functionality in the search panel:
Additional UI changes include:
The panel now passes its folder configuration through to the result rows.
The main window's rows do not currently receive that folder information, so the relative-path option is intentionally omitted there. This avoids presenting a relative-path action that would simply return the absolute path.
6. Shared macOS Relative Path Logic
Both keyboard shortcuts and context menu actions use a shared implementation:
FileDragView.relativeSpellingIts behavior matches the shell's Rust
relative_pathimplementation:/as a root that contains every absolute path.This keeps relative-path generation consistent across the macOS and Windows/Linux implementations.
Testing and Verification
Measured on the development machine:
Hardware and environment: Apple M1, 8 GB RAM, macOS 26.5.1.
Rust Tests
cargo test: 14 tests passed.copy_path_testscover:/as a root containing all absolute paths./.Additional Test Suites
node --test— 17 tests passed.node --check.Scope and Limitations
The following items remain unverified or have known platform-specific limitations:
copy_textimplementation is only compiled for Windows targets.\character will have its separators rewritten during relative-path formatting. This behavior exists in both implementations and is expected to be extremely uncommon.