Repository navigation
Fix /open-file re-inserting lone file when clearing the argument - #13017
Conversation
When a directory contains exactly one file, backspacing the `/open-file` argument back to empty re-triggered the auto-opened completions, which immediately re-inserted the only file — making it impossible to clear the argument to type a different path. The empty-argument auto-open used `CompletionsTrigger::Keybinding`, which treats a single prefix suggestion as an immediate insertion. That behavior is correct for an explicit user keybinding (Tab) but wrong for a system-initiated open. Add a dedicated `CompletionsTrigger::SlashCommandAutoOpen` variant that still generates file-path completions (same fallback strategy as Keybinding) but shows them in the menu instead of force-inserting a lone result. Closes warpdotdev#12990 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I reviewed this pull request and requested human review from: Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR adds a dedicated SlashCommandAutoOpen completions trigger so /open-file can auto-open file-path completions without treating a lone result like an explicit tab completion. The regression test covers the empty-argument case while preserving Keybinding single-result insertion behavior.
Concerns
- No blocking concerns found.
Verdict
Found: 0 critical, 0 important, 0 suggestions
Approve
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
acarl005
left a comment
There was a problem hiding this comment.
Thanks for the fix! The code is over-commented so please revise that and then afterwards I'll approve.
| // Use `SlashCommandAutoOpen` rather than `Keybinding` here: this open is | ||
| // triggered automatically by detecting an empty `/open-file` argument, not by | ||
| // an explicit user keybinding. With `Keybinding`, a directory containing a | ||
| // single file would have that file immediately re-inserted as the user | ||
| // backspaces the argument back to empty, making it impossible to clear (see | ||
| // #12990). `SlashCommandAutoOpen` still generates file-path completions but | ||
| // shows them in the menu instead of force-inserting a lone result. |
There was a problem hiding this comment.
| // Use `SlashCommandAutoOpen` rather than `Keybinding` here: this open is | |
| // triggered automatically by detecting an empty `/open-file` argument, not by | |
| // an explicit user keybinding. With `Keybinding`, a directory containing a | |
| // single file would have that file immediately re-inserted as the user | |
| // backspaces the argument back to empty, making it impossible to clear (see | |
| // #12990). `SlashCommandAutoOpen` still generates file-path completions but | |
| // shows them in the menu instead of force-inserting a lone result. |
Delete comment. You don't need to explain this variant in the caller. Explain it in the doc comment on the SlashCommandAutoOpen declaration.
| /// Completions opened automatically by a slash command (e.g. `/open-file` with an empty | ||
| /// argument), rather than by an explicit user keybinding. These generate results like | ||
| /// [`CompletionsTrigger::Keybinding`] (including the file-path fallback) but must not | ||
| /// auto-insert a lone result, otherwise the user can never clear the argument when only a | ||
| /// single completion is available. |
There was a problem hiding this comment.
| /// Completions opened automatically by a slash command (e.g. `/open-file` with an empty | |
| /// argument), rather than by an explicit user keybinding. These generate results like | |
| /// [`CompletionsTrigger::Keybinding`] (including the file-path fallback) but must not | |
| /// auto-insert a lone result, otherwise the user can never clear the argument when only a | |
| /// single completion is available. | |
| /// Completions opened automatically by a slash command. |
There was a problem hiding this comment.
One sentence will suffice here.
| // Regression test for #12990: when `/open-file` auto-opens completions because its argument | ||
| // is empty and the current directory contains exactly one file, that lone file must NOT be | ||
| // inserted automatically. Otherwise the user can never backspace the argument back to empty, | ||
| // because clearing it re-triggers the auto-open which immediately re-inserts the only file. | ||
| // The fix distinguishes the system-initiated open (`SlashCommandAutoOpen`, which shows the | ||
| // menu) from an explicit user keybinding (`Keybinding`, which still inserts a lone result). |
There was a problem hiding this comment.
| // Regression test for #12990: when `/open-file` auto-opens completions because its argument | |
| // is empty and the current directory contains exactly one file, that lone file must NOT be | |
| // inserted automatically. Otherwise the user can never backspace the argument back to empty, | |
| // because clearing it re-triggers the auto-open which immediately re-inserts the only file. | |
| // The fix distinguishes the system-initiated open (`SlashCommandAutoOpen`, which shows the | |
| // menu) from an explicit user keybinding (`Keybinding`, which still inserts a lone result). |
| // A `/open-file`-driven auto-open with a single file suggestion must leave the empty | ||
| // argument untouched. |
There was a problem hiding this comment.
| // A `/open-file`-driven auto-open with a single file suggestion must leave the empty | |
| // argument untouched. |
The assertions are self-documenting. No comment needed.
| // By contrast, an explicit user keybinding with a single prefix suggestion still inserts | ||
| // it, preserving normal tab-completion behavior. |
There was a problem hiding this comment.
| // By contrast, an explicit user keybinding with a single prefix suggestion still inserts | |
| // it, preserving normal tab-completion behavior. |
The assertions are self-documenting. No comment needed.
Per reviewer feedback on warpdotdev#13017: reduce the `SlashCommandAutoOpen` doc comment to one sentence, drop the explanatory comment at the call site, and remove the self-documenting comments from the regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Done — trimmed the over-commenting (one-line doc on the variant, dropped the call-site comment and the self-documenting test comments). Thanks for the review! |
Description
When the current directory contains exactly one file, the
/open-fileslash command would not let you delete the argument back to empty. Backspacing the auto-filled filename to empty re-triggered the auto-opened completions, which immediately re-inserted the only file — so you could never clear the field to type a different path (e.g. a dotfile or a path in another directory).Root cause: the empty-argument auto-open used
CompletionsTrigger::Keybinding, which treats a single prefix suggestion as an immediate insertion. That's correct for an explicit user keybinding (Tab) but wrong for a system-initiated open. This PR adds a dedicatedCompletionsTrigger::SlashCommandAutoOpenvariant that still generates file-path completions (same fallback strategy asKeybinding) but shows them in the menu instead of force-inserting a lone result.Linked Issue
Closes #12990
ready-to-specorready-to-implement.Testing
./script/runAdded a regression test,
test_open_slash_command_does_not_autofill_single_file_completion, asserting that aSlashCommandAutoOpenopen with a single file suggestion leaves the/open-fileargument empty, while aKeybindingopen still inserts the lone result. Manually verified before/after on a Linuxwarp-ossbuild in a directory containing a single file.Screenshots / Videos
Before (argument can't be cleared — the file snaps back):
warp-12990-BEFORE.mp4
After
warp-12990-AFTER.mp4
Agent Mode
CHANGELOG-BUG-FIX: Fixed
/open-filenot allowing the argument to be cleared when the current directory contains a single file.