diff options
author | Nathan Vegdahl | 2021-07-28 21:11:08 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-28 21:11:08 +0000 |
commit | a873e719d5dd1816434c16bb02d74f1e00ca847a (patch) | |
tree | 7ea6f6a37f5a7f9e12f3fab4c7e07cb21ae0ec0b /helix-term/src/keymap.rs | |
parent | aead4e69a66ba004aa34e5a1a59e05239117250e (diff) | |
parent | b90450b9e8b995e96a723a5d8c7b179ad2967c5a (diff) |
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
Diffstat (limited to 'helix-term/src/keymap.rs')
-rw-r--r-- | helix-term/src/keymap.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 93cc5328..95479340 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -234,6 +234,7 @@ pub struct Keymap { /// Always a Node #[serde(flatten)] root: KeyTrie, + /// Stores pending keys waiting for the next key #[serde(skip)] state: Vec<KeyEvent>, } @@ -250,6 +251,11 @@ impl Keymap { &self.root } + /// Returns list of keys waiting to be disambiguated. + pub fn pending(&self) -> &[KeyEvent] { + &self.state + } + /// Lookup `key` in the keymap to try and find a command to execute pub fn get(&mut self, key: KeyEvent) -> KeymapResult { let &first = self.state.get(0).unwrap_or(&key); @@ -292,6 +298,19 @@ impl Default for Keymap { #[serde(transparent)] pub struct Keymaps(pub HashMap<Mode, Keymap>); +impl Keymaps { + /// Returns list of keys waiting to be disambiguated in current mode. + pub fn pending(&self) -> &[KeyEvent] { + self.0 + .values() + .find_map(|keymap| match keymap.pending().is_empty() { + true => None, + false => Some(keymap.pending()), + }) + .unwrap_or_default() + } +} + impl Deref for Keymaps { type Target = HashMap<Mode, Keymap>; @@ -337,6 +356,7 @@ impl Default for Keymaps { "E" => move_next_long_word_end, "v" => select_mode, + "G" => goto_line, "g" => { "Goto" "g" => goto_file_start, "e" => goto_file_end, |