diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 2fdd08995940..b6d0b5069e83 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -331,6 +331,15 @@ impl Keymaps { self.sticky.as_ref() } + pub fn contains_key(&self, mode: Mode, key: KeyEvent) -> bool { + let keymaps = &*self.map(); + let keymap = &keymaps[&mode]; + keymap + .search(self.pending()) + .and_then(KeyTrie::node) + .is_some_and(|node| node.contains_key(&key)) + } + /// Lookup `key` in the keymap to try and find a command to execute. Escape /// key cancels pending keystrokes. If there are no pending keystrokes but a /// sticky node is in use, it will be cleared. diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index fef62a292910..bb749d2e7522 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -903,7 +903,9 @@ impl EditorView { fn command_mode(&mut self, mode: Mode, cxt: &mut commands::Context, event: KeyEvent) { match (event, cxt.editor.count) { // count handling - (key!(i @ '0'), Some(_)) | (key!(i @ '1'..='9'), _) => { + (key!(i @ '0'), Some(_)) | (key!(i @ '1'..='9'), _) + if !self.keymaps.contains_key(mode, event) => + { let i = i.to_digit(10).unwrap() as usize; cxt.editor.count = std::num::NonZeroUsize::new(cxt.editor.count.map_or(i, |c| c.get() * 10 + i));