Skip to content

Fix /open-file re-inserting lone file when clearing the argument - #13017

Merged
acarl005 merged 2 commits into
warpdotdev:masterfrom
AndreKalberer:andrekalberer/open-file-empty-arg
Jun 25, 2026
Merged

acarl005 merged 2 commits into
warpdotdev:masterfrom
AndreKalberer:andrekalberer/open-file-empty-arg

Conversation

@AndreKalberer

@AndreKalberer AndreKalberer commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

When the current directory contains exactly one file, the /open-file slash 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 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.

Linked Issue

Closes #12990

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below.

Testing

  • I have manually tested my changes locally with ./script/run

Added a regression test, test_open_slash_command_does_not_autofill_single_file_completion, asserting that a SlashCommandAutoOpen open with a single file suggestion leaves the /open-file argument empty, while a Keybinding open still inserts the lone result. Manually verified before/after on a Linux warp-oss build 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

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-BUG-FIX: Fixed /open-file not allowing the argument to be cleared when the current directory contains a single file.

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>
@cla-bot cla-bot Bot added the cla-signed label Jun 24, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jun 24, 2026
@AndreKalberer
AndreKalberer marked this pull request as ready for review June 24, 2026 21:04
@warp-for-oss

warp-for-oss Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

@AndreKalberer

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

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@warp-for-oss
warp-for-oss Bot requested a review from acarl005 June 24, 2026 21:07

@acarl005 acarl005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix! The code is over-commented so please revise that and then afterwards I'll approve.

Comment on lines +272 to +278
// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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.

Comment thread app/src/terminal/input.rs Outdated
Comment on lines +2087 to +2091
/// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One sentence will suffice here.

Comment thread app/src/terminal/input_tests.rs Outdated
Comment on lines +3510 to +3515
// 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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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).

Comment thread app/src/terminal/input_tests.rs Outdated
Comment on lines +3533 to +3534
// A `/open-file`-driven auto-open with a single file suggestion must leave the empty
// argument untouched.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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.

Comment thread app/src/terminal/input_tests.rs Outdated
Comment on lines +3551 to +3552
// By contrast, an explicit user keybinding with a single prefix suggestion still inserts
// it, preserving normal tab-completion behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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.

@acarl005 acarl005 self-assigned this Jun 25, 2026
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>
@AndreKalberer

Copy link
Copy Markdown
Contributor Author

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!

@acarl005
acarl005 enabled auto-merge (squash) June 25, 2026 19:31
@acarl005
acarl005 merged commit 4c39fe7 into warpdotdev:master Jun 25, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix | /open-file slash command doesn't allow deleting all characters when there's only 1 file in the cwd

2 participants