aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/keymap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/keymap.rs')
-rw-r--r--helix-term/src/keymap.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 93cc5328..7328e729 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>;