Skip to content

fix(engine): report Esc as inapplicable when there is nothing to cancel - #1285

Merged
kronberger-droid merged 1 commit into
nushell:mainfrom
Kiddo4993:fix/issue-990
Nov 2, 2026
Merged

kronberger-droid merged 1 commit into
nushell:mainfrom
Kiddo4993:fix/issue-990

Conversation

@Kiddo4993

Copy link
Copy Markdown
Contributor

Fixes #990.

In regular editing, ReedlineEvent::Esc always returned EventStatus::Handled, even when there was nothing to cancel. So a binding like

ReedlineEvent::UntilFound(vec![
    ReedlineEvent::Esc,
    ReedlineEvent::ExecuteHostCommand("esc".to_string()),
])

never got to the host command. That meant users couldn't keep Esc closing the completion menu and also give it a custom action.

Change

Esc still closes menus and clears the selection, just as before. Now it only returns Handled if a menu was active or the cursor held a selection. Otherwise it returns Inapplicable. This matches how MenuAccept, MenuPageNext, etc. already report "nothing to do", and it lets UntilFound move on to the next event.

Behaviour stays the same in these cases:

  • Vi and Helix send Esc inside Multiple([..., Repaint]), so the batch still counts as handled and still repaints.
  • Esc in history search mode is a separate handler and is untouched.
  • With nothing to cancel, a bare emacs Esc changed no state anyway. The only difference is that it no longer triggers a needless repaint.

Tests

Added engine tests for these cases:

  • Esc that closes a menu returns Handled.
  • Esc that clears a selection returns Handled.
  • Esc with nothing to cancel returns Inapplicable.
  • Under UntilFound, Esc falls through to the next event only when there is nothing to cancel.

I haven't been able to compile or run the tests in this environment.

Fixes #990


Happy to adjust anything or close it if it isn't a fit.

@fdncred

fdncred commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Isn't ReedlineEvent::ExecuteHostCommand("esc".to_string()), looking for an external command named esc? Does that exist?

@kronberger-droid

Copy link
Copy Markdown
Collaborator

I think that example is only reprensentational, and not really functional.
@fdncred

I will take a look soon, I might want it at a different place or at least extracted into a function. I will be comming back to you with a more detailed review soon.
@Kiddo4993.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

After some consideration it fine as is. I have now also built and tested it. Seems fine for me to land.

@kronberger-droid
kronberger-droid marked this pull request as ready for review November 2, 2026 09:57
@kronberger-droid

Copy link
Copy Markdown
Collaborator

My mistake, landed on the wrong PR. I am fine to land it.

@kronberger-droid
kronberger-droid merged commit 1d15862 into nushell:main Nov 2, 2026
16 checks passed
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.

Allow ESC to be binded to custom action, when not in tab complete, at least when nothing being inputed

3 participants