gpui: Only time out multi-stroke bindings when current prefix matches (#42659)

Part One for Resolving #10910

### Summary
Typing prefix (partial keybinding) will behave like Vim. No timeout
until you either finish the sequence or hit Escape, while ambiguous
sequences still auto-resolve after 1s.

### Description
This follow-up tweaks the which-key system first part groundwork so our
timeout behavior matches Vim’s expectations. Then we can implement the
UI part in the next step (reference latest comments in
https://github.com/zed-industries/zed/pull/34798)
- `DispatchResult` now reports when the current keystrokes are already a
complete binding in the active context stack (`pending_has_binding`). We
only start the 1s flush timer in that case. Pure prefixes or sequences
that only match in other contexts—stay pending indefinitely, so
leader-style combos like `space f g` no longer evaporate after a second.
- `Window::dispatch_key_event` cancels any prior timer before scheduling
a new one and only spawns the background flush task when
`pending_has_binding` is true. If there’s no matching binding, we keep
the pending keystrokes and rely on an explicit Escape or more typing to
resolve them.

Release Notes:

- Fixed multi-stroke keybindings so only ambiguous prefixes auto-trigger
after 1 s; unmatched prefixes now stay pending until canceled, matching
Vim-style leader behavior.
This commit is contained in:
Xipeng Jin
2025-11-20 19:42:56 -07:00
committed by GitHub
parent 2b9eeb9a30
commit b3ebcef5c6
4 changed files with 94 additions and 32 deletions
+1 -7
View File
@@ -22165,13 +22165,7 @@ impl Editor {
.pending_input_keystrokes()
.into_iter()
.flatten()
.filter_map(|keystroke| {
if keystroke.modifiers.is_subset_of(&Modifiers::shift()) {
keystroke.key_char.clone()
} else {
None
}
})
.filter_map(|keystroke| keystroke.key_char.clone())
.collect();
if !self.input_enabled || self.read_only || !self.focus_handle.is_focused(window) {