keymap: Rename KeyTrie::Leaf -> KeyTrie::MapppableCommand

The variant Sequence is technically also a leaf.
This commit is contained in:
gibbz00 2023-05-31 23:40:02 +02:00 committed by Blaž Hrastnik
parent a56af221d7
commit daea97a89f
2 changed files with 14 additions and 14 deletions

View File

@ -80,7 +80,7 @@ pub fn infobox(&self) -> Info {
let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
for (&key, trie) in self.iter() {
let desc = match trie {
KeyTrie::Leaf(cmd) => {
KeyTrie::MappableCommand(cmd) => {
if cmd.name() == "no_op" {
continue;
}
@ -139,7 +139,7 @@ fn deref_mut(&mut self) -> &mut Self::Target {
#[derive(Debug, Clone, PartialEq)]
pub enum KeyTrie {
Leaf(MappableCommand),
MappableCommand(MappableCommand),
Sequence(Vec<MappableCommand>),
Node(KeyTrieNode),
}
@ -168,7 +168,7 @@ fn visit_str<E>(self, command: &str) -> Result<Self::Value, E>
{
command
.parse::<MappableCommand>()
.map(KeyTrie::Leaf)
.map(KeyTrie::MappableCommand)
.map_err(E::custom)
}
@ -205,14 +205,14 @@ impl KeyTrie {
pub fn node(&self) -> Option<&KeyTrieNode> {
match *self {
KeyTrie::Node(ref node) => Some(node),
KeyTrie::Leaf(_) | KeyTrie::Sequence(_) => None,
KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None,
}
}
pub fn node_mut(&mut self) -> Option<&mut KeyTrieNode> {
match *self {
KeyTrie::Node(ref mut node) => Some(node),
KeyTrie::Leaf(_) | KeyTrie::Sequence(_) => None,
KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None,
}
}
@ -229,7 +229,7 @@ pub fn search(&self, keys: &[KeyEvent]) -> Option<&KeyTrie> {
trie = match trie {
KeyTrie::Node(map) => map.get(key),
// leaf encountered while keys left to process
KeyTrie::Leaf(_) | KeyTrie::Sequence(_) => None,
KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None,
}?
}
Some(trie)
@ -269,7 +269,7 @@ pub fn reverse_map(&self) -> ReverseKeymap {
// recursively visit all nodes in keymap
fn map_node(cmd_map: &mut ReverseKeymap, node: &KeyTrie, keys: &mut Vec<KeyEvent>) {
match node {
KeyTrie::Leaf(cmd) => match cmd {
KeyTrie::MappableCommand(cmd) => match cmd {
MappableCommand::Typable { name, .. } => {
cmd_map.entry(name.into()).or_default().push(keys.clone())
}
@ -371,7 +371,7 @@ pub fn get(&mut self, mode: Mode, key: KeyEvent) -> KeymapResult {
};
let trie = match trie_node.search(&[*first]) {
Some(KeyTrie::Leaf(ref cmd)) => {
Some(KeyTrie::MappableCommand(ref cmd)) => {
return KeymapResult::Matched(cmd.clone());
}
Some(KeyTrie::Sequence(ref cmds)) => {
@ -390,7 +390,7 @@ pub fn get(&mut self, mode: Mode, key: KeyEvent) -> KeymapResult {
}
KeymapResult::Pending(map.clone())
}
Some(KeyTrie::Leaf(cmd)) => {
Some(KeyTrie::MappableCommand(cmd)) => {
self.state.clear();
KeymapResult::Matched(cmd.clone())
}
@ -479,19 +479,19 @@ fn merge_partial_keys() {
// Assumes that `g` is a node in default keymap
assert_eq!(
keymap.root().search(&[key!('g'), key!('$')]).unwrap(),
&KeyTrie::Leaf(MappableCommand::goto_line_end),
&KeyTrie::MappableCommand(MappableCommand::goto_line_end),
"Leaf should be present in merged subnode"
);
// Assumes that `gg` is in default keymap
assert_eq!(
keymap.root().search(&[key!('g'), key!('g')]).unwrap(),
&KeyTrie::Leaf(MappableCommand::delete_char_forward),
&KeyTrie::MappableCommand(MappableCommand::delete_char_forward),
"Leaf should replace old leaf in merged subnode"
);
// Assumes that `ge` is in default keymap
assert_eq!(
keymap.root().search(&[key!('g'), key!('e')]).unwrap(),
&KeyTrie::Leaf(MappableCommand::goto_last_line),
&KeyTrie::MappableCommand(MappableCommand::goto_last_line),
"Old leaves in subnode should be present in merged node"
);
@ -523,7 +523,7 @@ fn order_should_be_set() {
.root()
.search(&[key!(' '), key!('s'), key!('v')])
.unwrap(),
&KeyTrie::Leaf(MappableCommand::vsplit),
&KeyTrie::MappableCommand(MappableCommand::vsplit),
"Leaf should be present in merged subnode"
);
// Make sure an order was set during merge

View File

@ -81,7 +81,7 @@ macro_rules! alt {
#[macro_export]
macro_rules! keymap {
(@trie $cmd:ident) => {
$crate::keymap::KeyTrie::Leaf($crate::commands::MappableCommand::$cmd)
$crate::keymap::KeyTrie::MappableCommand($crate::commands::MappableCommand::$cmd)
};
(@trie