Skip to content

feat(menu): add MenuAccept to take a completion without submitting - #1203

Merged
kronberger-droid merged 2 commits into
nushell:mainfrom
kronberger-droid:menu-accept
Sep 8, 2026
Merged

kronberger-droid merged 2 commits into
nushell:mainfrom
kronberger-droid:menu-accept

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enter over an open menu accepts the highlighted item, but the same key submits the line once no menu is open,
so there is no event a user can bind to "accept the completion, then keep typing".
Two stale PRs ran into that from different sides:
#965 wanted a zsh-style space that accepts and types itself and had to invent SubmitOrSpace for it,
#821 wanted an always-open menu and had to invent its own MenuAccept so Enter could stay free for submit.

This is the small shared piece: ReedlineEvent::MenuAccept.
It does what Enter does while a menu is open, splice the selection and deactivate, and stops there.
It reports Inapplicable when no menu is active or the active one has no values,
so it composes with UntilFound and Multiple like the other menu events.

New ReedlineEvent variant, thus a public API addition. No default keybinding changes and no observable change for anyone not binding it.

Before

Accepting a menu item is only reachable through Enter/Submit, which submit the buffer when the menu happens to be closed.

After

keybindings.add_binding(
    KeyModifiers::NONE,
    KeyCode::Char(' '),
    ReedlineEvent::Multiple(vec![
        ReedlineEvent::MenuAccept,
        ReedlineEvent::Edit(vec![EditCommand::InsertChar(' ')]),
    ]),
);

Space accepts the highlighted completion and types itself, and is a plain space when no menu is open.
An empty menu is left alone rather than closed, so the keypress is not spent on a menu with nothing in it,
which is the same direction #1175 takes the Enter arm.

Additional notes

Supersedes #965. First piece of #821, tracked in #356.

`Enter` over an open menu accepts the highlighted item, but with no menu
it submits the line, so nothing can be bound to "accept, then keep
typing". nushell#965 tried a `SubmitOrSpace` event for a zsh-style space and
had to bolt the space onto it; nushell#821 needed the same accept for an
always-open menu. One event that stops after the accept covers both as
a keybinding, `Multiple([MenuAccept, InsertChar ' '])`.

An empty menu reports inapplicable instead of closing, since spending
the keypress on an invisible menu is the bug nushell#1175 is fixing in the
`Enter` arm.
@kronberger-droid
kronberger-droid marked this pull request as ready for review September 8, 2026 07:50
@kronberger-droid
kronberger-droid merged commit 1585b51 into nushell:main Sep 8, 2026
7 checks passed
kronberger-droid added a commit to nushell/nushell that referenced this pull request Sep 9, 2026
## Description

Bumps `reedline` from `a8e9364` to `06bf606`:

- `3eb9942` fix(history): match cwd prefix literally in sqlite search
(nushell/reedline#778)
- `b582ddb` feat(editor): add access to the command line selection
(nushell/reedline#1200)
- `aae283d` feat(editor): make copy selection report failure without
selection (nushell/reedline#1166)
- `87f4d79` fix(painter): re-use a bottom-row prompt if the cursor
returns unmoved (nushell/reedline#1201)
- `1585b51` feat(menu): add MenuAccept to take a completion without
submitting (nushell/reedline#1203)
- `06bf606` feat(vi): read an unbound Alt-<char> as Esc then <char>
(nushell/reedline#1207)

`MenuAccept` is the only new event in that range, thus the second commit
wires it into `reedline_config.rs`.

## User-facing changes (Release notes)

Added the `MenuAccept` keybinding event.
It takes the highlighted completion into the buffer and closes the menu
without submitting the line.
@kronberger-droid
kronberger-droid deleted the menu-accept branch September 15, 2026 22:10
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