Don't let a menu with no suggestions swallow Enter - #1175
Conversation
…1203) * feat(menu): add MenuAccept to take a completion without submitting `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". #965 tried a `SubmitOrSpace` event for a zsh-style space and had to bolt the space onto it; #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 #1175 is fixing in the `Enter` arm. * test(menu): pin MenuAccept under UntilFound next to the Multiple case
|
Just needs a rebase, then I am fine to land it. |
The completion menu stays active while the user types past it, and any Enter/Submit/SubmitOrNewline while a menu is active is routed to the menu. A menu whose filtered suggestions are empty has nothing to accept, so the keypress simply died: the line did not run and nothing visibly happened, leaving Enter to work only on the second press. The guard now ignores active menus with no values, so the event falls through to the normal submit path, and submit_buffer closes any menu that let a submit through so it cannot stay active into the next line's editing.
b64bd30 to
f03d265
Compare
|
Yeah. |
|
Happy to take that. Worth noting the two are not quite identical today: the guard filters on I will send it as a follow-up. |
|
Sent it: #1210. The |
The symptom
With a completion menu registered, Enter sometimes appears dead: the line doesn't run, nothing is inserted, and a second Enter is needed. Repro:
The mechanism
The menu stays active from the first Tab until Esc/Enter/empty-buffer, and the
Enter | Submit | SubmitOrNewlinearm consumes the event for any active menu — including one with zero filtered values, wherereplace_in_bufferhas nothing to accept. The keypress is spent deactivating an invisible menu.The change
submit_bufferdeactivates menus, so a menu that let a submit through can't stay active into the next line's editing.Two tests: the empty-menu case directly, and the full reported shape (Tab mid-line, type on, Enter runs the line).
cargo fmt --all,cargo clippy --locked --all-targets --all-features(0 warnings), and the test suite pass; the pre-existing macOS-only parallel flake in the system-clipboard tests is unrelated.Found while building a SQL REPL on reedline (duckdb-harbor's pilot), where a stale menu turned end-of-statement Enters into no-ops. Diagnosed and written with AI assistance; verified by the suite here and by daily use downstream.