on master help sign in
keymap: Rename KeyTrie::Leaf -> KeyTrie::MapppableCommand
daea97agibbz00
helix-term/src/keymap.rs+13−13
@@ -80,7 +80,7 @@ impl KeyTrieNode {
80 let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
80 let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
81 for (&key, trie) in self.iter() {
81 for (&key, trie) in self.iter() {
82 let desc = match trie {
82 let desc = match trie {
83− KeyTrie::Leaf(cmd) => {
83+ KeyTrie::MappableCommand(cmd) => {
84 if cmd.name() == "no_op" {
84 if cmd.name() == "no_op" {
85 continue;
85 continue;
86 }
86 }
@@ -139,7 +139,7 @@ impl DerefMut for KeyTrieNode {
139
139
140#[derive(Debug, Clone, PartialEq)]
140#[derive(Debug, Clone, PartialEq)]
141pub enum KeyTrie {
141pub enum KeyTrie {
142− Leaf(MappableCommand),
142+ MappableCommand(MappableCommand),
143 Sequence(Vec<MappableCommand>),
143 Sequence(Vec<MappableCommand>),
144 Node(KeyTrieNode),
144 Node(KeyTrieNode),
145}
145}
@@ -168,7 +168,7 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
168 {
168 {
169 command
169 command
170 .parse::<MappableCommand>()
170 .parse::<MappableCommand>()
171− .map(KeyTrie::Leaf)
171+ .map(KeyTrie::MappableCommand)
172 .map_err(E::custom)
172 .map_err(E::custom)
173 }
173 }
174
174
@@ -205,14 +205,14 @@ impl KeyTrie {
205 pub fn node(&self) -> Option<&KeyTrieNode> {
205 pub fn node(&self) -> Option<&KeyTrieNode> {
206 match *self {
206 match *self {
207 KeyTrie::Node(ref node) => Some(node),
207 KeyTrie::Node(ref node) => Some(node),
208− KeyTrie::Leaf(_) | KeyTrie::Sequence(_) => None,
208+ KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None,
209 }
209 }
210 }
210 }
211
211
212 pub fn node_mut(&mut self) -> Option<&mut KeyTrieNode> {
212 pub fn node_mut(&mut self) -> Option<&mut KeyTrieNode> {
213 match *self {
213 match *self {
214 KeyTrie::Node(ref mut node) => Some(node),
214 KeyTrie::Node(ref mut node) => Some(node),
215− KeyTrie::Leaf(_) | KeyTrie::Sequence(_) => None,
215+ KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None,
216 }
216 }
217 }
217 }
218
218
@@ -229,7 +229,7 @@ impl KeyTrie {
229 trie = match trie {
229 trie = match trie {
230 KeyTrie::Node(map) => map.get(key),
230 KeyTrie::Node(map) => map.get(key),
231 // leaf encountered while keys left to process
231 // leaf encountered while keys left to process
232− KeyTrie::Leaf(_) | KeyTrie::Sequence(_) => None,
232+ KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None,
233 }?
233 }?
234 }
234 }
235 Some(trie)
235 Some(trie)
@@ -269,7 +269,7 @@ impl Keymap {
269 // recursively visit all nodes in keymap
269 // recursively visit all nodes in keymap
270 fn map_node(cmd_map: &mut ReverseKeymap, node: &KeyTrie, keys: &mut Vec<KeyEvent>) {
270 fn map_node(cmd_map: &mut ReverseKeymap, node: &KeyTrie, keys: &mut Vec<KeyEvent>) {
271 match node {
271 match node {
272− KeyTrie::Leaf(cmd) => match cmd {
272+ KeyTrie::MappableCommand(cmd) => match cmd {
273 MappableCommand::Typable { name, .. } => {
273 MappableCommand::Typable { name, .. } => {
274 cmd_map.entry(name.into()).or_default().push(keys.clone())
274 cmd_map.entry(name.into()).or_default().push(keys.clone())
275 }
275 }
@@ -371,7 +371,7 @@ impl Keymaps {
371 };
371 };
372
372
373 let trie = match trie_node.search(&[*first]) {
373 let trie = match trie_node.search(&[*first]) {
374− Some(KeyTrie::Leaf(ref cmd)) => {
374+ Some(KeyTrie::MappableCommand(ref cmd)) => {
375 return KeymapResult::Matched(cmd.clone());
375 return KeymapResult::Matched(cmd.clone());
376 }
376 }
377 Some(KeyTrie::Sequence(ref cmds)) => {
377 Some(KeyTrie::Sequence(ref cmds)) => {
@@ -390,7 +390,7 @@ impl Keymaps {
390 }
390 }
391 KeymapResult::Pending(map.clone())
391 KeymapResult::Pending(map.clone())
392 }
392 }
393− Some(KeyTrie::Leaf(cmd)) => {
393+ Some(KeyTrie::MappableCommand(cmd)) => {
394 self.state.clear();
394 self.state.clear();
395 KeymapResult::Matched(cmd.clone())
395 KeymapResult::Matched(cmd.clone())
396 }
396 }
@@ -479,19 +479,19 @@ mod tests {
479 // Assumes that `g` is a node in default keymap
479 // Assumes that `g` is a node in default keymap
480 assert_eq!(
480 assert_eq!(
481 keymap.root().search(&[key!('g'), key!('$')]).unwrap(),
481 keymap.root().search(&[key!('g'), key!('$')]).unwrap(),
482− &KeyTrie::Leaf(MappableCommand::goto_line_end),
482+ &KeyTrie::MappableCommand(MappableCommand::goto_line_end),
483 "Leaf should be present in merged subnode"
483 "Leaf should be present in merged subnode"
484 );
484 );
485 // Assumes that `gg` is in default keymap
485 // Assumes that `gg` is in default keymap
486 assert_eq!(
486 assert_eq!(
487 keymap.root().search(&[key!('g'), key!('g')]).unwrap(),
487 keymap.root().search(&[key!('g'), key!('g')]).unwrap(),
488− &KeyTrie::Leaf(MappableCommand::delete_char_forward),
488+ &KeyTrie::MappableCommand(MappableCommand::delete_char_forward),
489 "Leaf should replace old leaf in merged subnode"
489 "Leaf should replace old leaf in merged subnode"
490 );
490 );
491 // Assumes that `ge` is in default keymap
491 // Assumes that `ge` is in default keymap
492 assert_eq!(
492 assert_eq!(
493 keymap.root().search(&[key!('g'), key!('e')]).unwrap(),
493 keymap.root().search(&[key!('g'), key!('e')]).unwrap(),
494− &KeyTrie::Leaf(MappableCommand::goto_last_line),
494+ &KeyTrie::MappableCommand(MappableCommand::goto_last_line),
495 "Old leaves in subnode should be present in merged node"
495 "Old leaves in subnode should be present in merged node"
496 );
496 );
497
497
@@ -523,7 +523,7 @@ mod tests {
523 .root()
523 .root()
524 .search(&[key!(' '), key!('s'), key!('v')])
524 .search(&[key!(' '), key!('s'), key!('v')])
525 .unwrap(),
525 .unwrap(),
526− &KeyTrie::Leaf(MappableCommand::vsplit),
526+ &KeyTrie::MappableCommand(MappableCommand::vsplit),
527 "Leaf should be present in merged subnode"
527 "Leaf should be present in merged subnode"
528 );
528 );
529 // Make sure an order was set during merge
529 // Make sure an order was set during merge
helix-term/src/keymap/macros.rs+1−1
@@ -81,7 +81,7 @@ macro_rules! alt {
81#[macro_export]
81#[macro_export]
82macro_rules! keymap {
82macro_rules! keymap {
83 (@trie $cmd:ident) => {
83 (@trie $cmd:ident) => {
84− $crate::keymap::KeyTrie::Leaf($crate::commands::MappableCommand::$cmd)
84+ $crate::keymap::KeyTrie::MappableCommand($crate::commands::MappableCommand::$cmd)
85 };
85 };
86
86
87 (@trie
87 (@trie