From 73d8700f601fd0e8bedd19daf1bb094e1e5c0d0b Mon Sep 17 00:00:00 2001 From: Matthew Cheely Date: Sat, 24 Sep 2022 21:31:15 -0400 Subject: [PATCH] refactor keymap map visitor to reduce # of cases --- helix-term/src/keymap.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index f157e2fee..98521eb3d 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -218,20 +218,16 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { match command { None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), Some(cmd) => { - if label.is_empty() { - Ok(KeyTrie::Leaf(cmd)) + let status = (cmd, label.is_empty()); + if let (MappableCommand::Typable { name, args, .. }, false) = status { + Ok(MappableCommand::Typable { + name, + args, + doc: label.to_string(), + }) + .map(KeyTrie::Leaf) } else { - match cmd { - MappableCommand::Typable { name, args, .. } => { - Ok(MappableCommand::Typable { - name, - args, - doc: label.to_string(), - }) - .map(KeyTrie::Leaf) - } - MappableCommand::Static { .. } => Ok(KeyTrie::Leaf(cmd)), - } + Ok(KeyTrie::Leaf(status.0)) } } }