refactor keymap map visitor to reduce # of cases

pull/3958/head
Matthew Cheely 2022-09-24 21:31:15 -04:00
parent a7f603361a
commit a5d1c0571a
1 changed files with 9 additions and 13 deletions

View File

@ -218,20 +218,16 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
match command { match command {
None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))),
Some(cmd) => { Some(cmd) => {
if label.is_empty() { let status = (cmd, label.is_empty());
Ok(KeyTrie::Leaf(cmd)) if let (MappableCommand::Typable { name, args, .. }, false) = status {
} else {
match cmd {
MappableCommand::Typable { name, args, .. } => {
Ok(MappableCommand::Typable { Ok(MappableCommand::Typable {
name, name,
args, args,
doc: label.to_string(), doc: label.to_string(),
}) })
.map(KeyTrie::Leaf) .map(KeyTrie::Leaf)
} } else {
MappableCommand::Static { .. } => Ok(KeyTrie::Leaf(cmd)), Ok(KeyTrie::Leaf(status.0))
}
} }
} }
} }