@@ -300,7 +300,7 @@ impl KeyTrie {
302#[derive(Debug, Clone, PartialEq)]
302#[derive(Debug, Clone, PartialEq)]
303−pub enum KeymapResultKind {
303+pub enum KeymapResult {
304 /// Needs more keys to execute a command. Contains valid keys for next keystroke.
304 /// Needs more keys to execute a command. Contains valid keys for next keystroke.
305 Pending(KeyTrieNode),
305 Pending(KeyTrieNode),
306 Matched(MappableCommand),
306 Matched(MappableCommand),
@@ -313,20 +313,6 @@ pub enum KeymapResultKind {
313 Cancelled(Vec<KeyEvent>),
313 Cancelled(Vec<KeyEvent>),
316−/// Returned after looking up a key in [`Keymap`]. The `sticky` field has a
317−/// reference to the sticky node if one is currently active.
319−pub struct KeymapResult<'a> {
320− pub kind: KeymapResultKind,
321− pub sticky: Option<&'a KeyTrieNode>,
324−impl<'a> KeymapResult<'a> {
325− pub fn new(kind: KeymapResultKind, sticky: Option<&'a KeyTrieNode>) -> Self {
326− Self { kind, sticky }
330#[derive(Debug, Clone, PartialEq, Deserialize)]
316#[derive(Debug, Clone, PartialEq, Deserialize)]
331#[serde(transparent)]
317#[serde(transparent)]
332pub struct Keymap {
318pub struct Keymap {
@@ -437,11 +423,8 @@ impl Keymaps {
438 if key!(Esc) == key {
424 if key!(Esc) == key {
439 if !self.state.is_empty() {
425 if !self.state.is_empty() {
440− return KeymapResult::new(
441− // Note that Esc is not included here
426+ // Note that Esc is not included here
442− KeymapResultKind::Cancelled(self.state.drain(..).collect()),
427+ return KeymapResult::Cancelled(self.state.drain(..).collect());
446 self.sticky = None;
429 self.sticky = None;
@@ -454,15 +437,12 @@ impl Keymaps {
455 let trie = match trie_node.search(&[*first]) {
438 let trie = match trie_node.search(&[*first]) {
456 Some(KeyTrie::Leaf(ref cmd)) => {
439 Some(KeyTrie::Leaf(ref cmd)) => {
457− return KeymapResult::new(KeymapResultKind::Matched(cmd.clone()), self.sticky())
440+ return KeymapResult::Matched(cmd.clone());
459 Some(KeyTrie::Sequence(ref cmds)) => {
442 Some(KeyTrie::Sequence(ref cmds)) => {
460− return KeymapResult::new(
461− KeymapResultKind::MatchedSequence(cmds.clone()),
443+ return KeymapResult::MatchedSequence(cmds.clone());
465− None => return KeymapResult::new(KeymapResultKind::NotFound, self.sticky()),
445+ None => return KeymapResult::NotFound,
466 Some(t) => t,
446 Some(t) => t,
@@ -473,23 +453,17 @@ impl Keymaps {
473 self.state.clear();
453 self.state.clear();
474 self.sticky = Some(map.clone());
454 self.sticky = Some(map.clone());
476− KeymapResult::new(KeymapResultKind::Pending(map.clone()), self.sticky())
456+ KeymapResult::Pending(map.clone())
478 Some(&KeyTrie::Leaf(ref cmd)) => {
458 Some(&KeyTrie::Leaf(ref cmd)) => {
479 self.state.clear();
459 self.state.clear();
480− return KeymapResult::new(KeymapResultKind::Matched(cmd.clone()), self.sticky());
460+ KeymapResult::Matched(cmd.clone())
482 Some(&KeyTrie::Sequence(ref cmds)) => {
462 Some(&KeyTrie::Sequence(ref cmds)) => {
483 self.state.clear();
463 self.state.clear();
485− KeymapResultKind::MatchedSequence(cmds.clone()),
464+ KeymapResult::MatchedSequence(cmds.clone())
489− None => KeymapResult::new(
490− KeymapResultKind::Cancelled(self.state.drain(..).collect()),
466+ None => KeymapResult::Cancelled(self.state.drain(..).collect()),
@@ -901,19 +875,19 @@ mod tests {
902 let keymap = &mut merged_config.keys;
876 let keymap = &mut merged_config.keys;
903 assert_eq!(
877 assert_eq!(
904− keymap.get(Mode::Normal, key!('i')).kind,
878+ keymap.get(Mode::Normal, key!('i')),
905− KeymapResultKind::Matched(MappableCommand::normal_mode),
879+ KeymapResult::Matched(MappableCommand::normal_mode),
906 "Leaf should replace leaf"
880 "Leaf should replace leaf"
908 assert_eq!(
882 assert_eq!(
909− keymap.get(Mode::Normal, key!('无')).kind,
883+ keymap.get(Mode::Normal, key!('无')),
910− KeymapResultKind::Matched(MappableCommand::insert_mode),
884+ KeymapResult::Matched(MappableCommand::insert_mode),
911 "New leaf should be present in merged keymap"
885 "New leaf should be present in merged keymap"
913 // Assumes that z is a node in the default keymap
887 // Assumes that z is a node in the default keymap
914 assert_eq!(
888 assert_eq!(
915− keymap.get(Mode::Normal, key!('z')).kind,
889+ keymap.get(Mode::Normal, key!('z')),
916− KeymapResultKind::Matched(MappableCommand::jump_backward),
890+ KeymapResult::Matched(MappableCommand::jump_backward),
917 "Leaf should replace node"
891 "Leaf should replace node"