feat(input): auto-wrap drag-and-dropped file paths with @[] syntax#2808
Conversation
When a user drags and drops a file onto the terminal, the terminal pastes the raw file path as text. Forge requires @[path] syntax to recognise file references, so dropped files were silently ignored. This commit detects bare file paths and wraps them at paste time so the @[...] reference appears immediately in the input buffer: - Reedline editor (editor.rs): a custom ForgeEditMode wraps the default Emacs mode and intercepts crossterm Paste events. The pasted text is transformed before it reaches the reedline buffer, giving the user instant visual feedback. - Zsh shell plugin (bindings.zsh): the forge-bracketed-paste widget intercepts pasted text and wraps it when it points to an existing file. Co-Authored-By: ForgeCode <noreply@forgecode.dev>
strip_surrounding_quotes would panic on a single quote character because slicing s[1..0] is an invalid range. Add an early return for strings shorter than 2 characters. Co-Authored-By: ForgeCode <noreply@forgecode.dev>
- Remove fast path in wrap_pasted_text that discarded surrounding whitespace from the original paste content. - Add double-quote stripping in the zsh bracketed-paste widget to match the Rust implementation which already handled both quote styles. Co-Authored-By: ForgeCode <noreply@forgecode.dev>
9715d7f to
3f4b3e8
Compare
|
This also pretty much addresses #2811 , as you can copy an image anywhere and just paste it with the proper syntax now |
|
@tapizquent-gail Does this work with zsh plugin as well? |
Yes. Screen.Recording.2026-04-02.at.21.42.40.mov |
- Fix Rust wrap_pasted_text to try entire paste as a single path before token splitting, handling bare paths with spaces - Add backslash-escape awareness: strip '\ ' to ' ' before is_file() checks so terminal drag-and-drop (Ghostty, iTerm2) works correctly - Update tokenizer to treat backslash-space as non-boundary so escaped paths stay as a single token - Fix zsh forge-bracketed-paste to handle backslash-escaped and quoted paths with spaces - Add forge-accept-line fallback (_forge_wrap_file_paths) for terminals that don't emit bracketed-paste on drag-and-drop (e.g. JetBrains) - Only trigger @[] wrapping when zsh buffer starts with ':' (sentinel) - Add zsh test script (scripts/test-zsh-utils.sh) with 21 correctness and performance tests Co-Authored-By: ForgeCode <noreply@forgecode.dev>
Move all file path detection and @[...] wrapping logic from the zsh plugin into Rust, exposed as a new `forge zsh format --buffer <text>` CLI subcommand. This addresses the PR review comment requesting a single well-tested implementation. Changes: - Add ZshCommandGroup::Format variant with --buffer arg to CLI - Make wrap_pasted_text() public so it can be called from the dispatch - Simplify forge-bracketed-paste widget to delegate to forge zsh format - Simplify forge-accept-line dispatcher to delegate to forge zsh format - Remove _forge_wrap_file_paths and _forge_unescape_backslashes from zsh helpers (139 lines of zsh replaced by a one-line CLI call) - Update test script to exercise forge zsh format end-to-end - Add CLI parsing test for the new subcommand Net: -156 lines (79 added, 235 removed) Co-Authored-By: ForgeCode <noreply@forgecode.dev>
|
Improved, now works with paths or files containing spaces and uses rust syntax for |
|
@tapizquent-gail I think we need a better way to make it work with RustRover and VSCode. We need to insert in the terminal with proper syntax highlighting to suggest that that a file has been attached. |
When a user drags and drops a file onto the terminal, the terminal pastes the raw file path as text. Forge requires @[path] syntax to recognise file references, so dropped files were silently ignored.
This commit detects bare file paths and wraps them at paste time so the @[...] reference appears immediately in the input buffer:
Screen.Recording.2026-04-02.at.17.47.39.mov