Skip to content

fix: support enter as the accept suggestion binding - #489

Closed
Caner Patır (CanerPatir) wants to merge 1 commit into
microsoft:mainfrom
CanerPatir:fix/enter-accept-keeps-command-state
Closed

Caner Patır (CanerPatir) wants to merge 1 commit into
microsoft:mainfrom
CanerPatir:fix/enter-accept-keeps-command-state

Conversation

@CanerPatir

Copy link
Copy Markdown

Problem

Binding acceptSuggestion to return in the config does not work as expected:

[bindings.acceptSuggestion]
key = "return"

Accepting a suggestion with enter (e.g. git chec → checkout) inserts it, but no further suggestions are shown for the rest of the line (branches never appear after git checkout ). With tab, the same flow works.

SuggestionManager.update() calls term.clearCommand() on every enter before evaluating bindings, so the tracked command is reset even when enter is consumed as the accept key.

Fix

  • Clear the command on enter only when the key press was not handled by a binding.
  • When enter is the accept key and the active token is empty, let enter run the command unless a suggestion was explicitly selected with the navigation keys. Without this, a completed line (git checkout feature-x ) can't be executed with enter, because the next-argument suggestions are always visible.

Behavior with the default tab binding is unchanged.

Testing

  • Added unit tests in src/tests/utils/suggestionManager.test.ts covering accept-on-enter, enter not consumed by a binding, enter on an empty token, and enter after navigating. The accept-on-enter test fails without the fix.
  • npm test and lint pass.
  • Manually verified in zsh with enter bound to accept: git chec ⏎ → git checkout with branch suggestions, f ↓ ⏎ → git checkout feature-beta, ⏎ → command runs.

When acceptSuggestion is bound to "return", accepting a suggestion also
cleared the tracked command because update() reset the command state on
every enter before evaluating bindings. Suggestions then stopped showing
for the rest of the line.

Clear the command on enter only when the key press was not consumed by a
binding. With enter bound to accept, pressing it on an empty token now
runs the command unless a suggestion was explicitly selected with the
navigation keys, so a completed line can still be executed with enter.
@CanerPatir
Caner Patır (CanerPatir) deleted the fix/enter-accept-keeps-command-state branch October 15, 2026 13:23
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.

1 participant