From e9320ebdc7d2834750e88888a07a4242e2de951d 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 c470b9732..804171386 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -205,20 +205,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)) } } }