Repository navigation
core: Deliver typed characters to typeahead - #4023
Merged
Merged
Conversation
Add on_key_char: the text a key types on the layout in use, in its case, for a binding taking typed characters while no text input edits or input method composes. Every backend matches it after the keystroke bindings. Select, Combobox, Menu, Tree and Command typeahead listen to it instead of 36 fixed keys, and Space adds to a typeahead string in progress. Fixes #3991 Agent: rust-maintainer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent: rust-maintainer
Member
Author
|
Merged
|
KeyFocus is non_exhaustive, so the Windows and Linux keymaps can't use a struct expression for it. The gpui typed-key test counted events sent to an engine it never starts; check what each key returns instead. Agent: rust-maintainer
madcodelife
added a commit
to longbridge/nsh-compat
that referenced
this pull request
Dec 2, 2026
## What The simulated keyboard of the apps check (`Views::press_key`) now delivers the character a key types to a binding of typed characters. When no keystroke binding takes a `Key::Char`, it types its character on the US layout (Shift's character with Shift) and matches it with `Keymap::find_typed`. When a binding takes it, `typed_payload(id, text)` is reported to the root as a `KeyCommand` and the key is consumed. This mirrors nsh's headless driver (`Headless::send_typed`) from longbridge/nsh#4023. ## Why longbridge/nsh#4023 moved typeahead (`Select`, `Combobox`, `Menu`, `Tree`, `Command`) from keystroke bindings of `a`–`z` / `0`–`9` to typed characters (`on_key_char`). Since then, a letter pressed here reaches no binding, and the Compat check on nsh `main` fails: ``` case-browser: step 59 `expect Log: chose DeskItem`: not shown ``` In that case, `key d` on a menu opened by a press should move the focus to `DeskItem`, and `key enter` should choose it. ## Test plan Against nsh `main` (ea517c992) with this change: - `NSH_COMPAT_APP=browser cargo xtask compat -v`: passes (step 59 included). - `cargo xtask compat -v`: 39 passed, 0 failed. - `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings`: clean. Without this change, the browser case fails at step 59 on nsh `main` and at longbridge/nsh@a534ec3a1. It passes at that commit's parent (5f62f41bd).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Typeahead in
Select,Combobox,Menu,TreeandCommandbound 36 fixed keys (a–z,0–9). Shift capitals, non-US layouts and accented letters never reached it, and no extra bindings can fix that: a keystroke names a US key position, not the text it types. This PR adds a small core channel for typed characters, as the decision on #3991 asked:nsh-core):on_key_char(KeyOptions, |text| ..)runs a handler with the text a key types on the layout in use, in its case (Shift+A is"A", a French key"é", a Russian key"ж"). It fires only for a key that no keystroke binding took. It does not fire while a text input edits or an input method composes, for Space alone, for named keys or control characters, or with Command, or with Control/Alt unless AltGr typed the key. Option counts on Apple platforms, where it types characters. The key is consumed. Bindings live in the root keymap's own list. The platform matches them withKeymap::find_typedafter the keystroke bindings, and reports them through the existing rootKeyCommandevent with a{ id, text }payload.bind_typeahead(with listbox: Take a capital and a Space in typeahead #4010's structure: reset when the active item changes, Space inside a string) now listens toon_key_charinstead of bindingTYPEAHEAD_KEYS. While a typeahead string is in progress (a character within the 1 s typeahead pause), Space adds a space instead of choosing or opening:ice creaches "Ice cream".find_typedwhere it already matches the keymap:NSEvent.charactersWM_CHAR, AltGr as Ctrl+Alt, noVK_PROCESSKEYKeystroke::key_charkey, not whileisComposingUIKey.charactersKeyCode::Charpress_char(text)for keys no keystroke namesPublic API
nsh_core::element::on_key_char(also in the prelude). Rust only; TSX has no equivalent in this PR.#[doc(hidden)]:Keymap::with_typed,Keymap::takes_typed,Keymap::find_typed,keymap::typed_payload.Headless::press_char.Compatibility: JS never sees the new payload, because typed-character bindings are views' bindings with ids ≥ 2^31 that the core handles itself. Existing JS
onKeyCommandpayloads are unchanged. Nothing is registered innsh-compat, since no release is recorded yet.on_key_charis new Rust surface to name-check before the 0.9.0 freeze.Tests
nsh-corekeymap: typed text goes to the newest binding of its window, never while editing, and is filtered by modifiers (Shift, Cmd, Ctrl, Alt, AltGr, Option on Apple).nsh-baseselect:typeahead_takes_the_characters_a_key_types(Shift+I,é,Б),a_shortcut_with_command_or_control_is_not_typed; the space-in-a-string tests from listbox: Take a capital and a Space in typeahead #4010 (typeahead_takes_a_capital_and_a_space_while_typing,typeahead_on_the_closed_trigger_takes_a_space_while_typing) now run throughon_key_char.WM_CHARfiltering, GTK keyval text, GPUIkey_char, webkey/composition, TUI).Verification gap: no real-window check yet on Linux, Windows (embedded) or macOS; that follows on this PR.
Fixes #3991
🤖 Noop (rust-maintainer) · Opus 5.5 acting for @huacnlee