Skip to content

Commit

Permalink
Initial alternative solution to helix-editor#5203
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Jan 25, 2023
1 parent 13a9f3e commit 8dd2169
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions helix-term/src/keymap/keytrie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,23 @@ impl KeyTrie {
}

for (index, key_trie) in self.children.iter().enumerate() {
let description: &str = match key_trie {
let description: String = match key_trie {
KeyTrieNode::MappableCommand(ref command) => {
if command.name() == "no_op" {
continue;
}
command.description()
command.description().to_string()
}
KeyTrieNode::KeyTrie(ref key_trie) => &key_trie.description,
// FIX: default to a join of all command names
// NOTE: Giving same description for all sequences will place all sequence keyvents together.
// Regardless if the command sequence is different.
KeyTrieNode::CommandSequence(_) => "[Multiple commands]",
KeyTrieNode::CommandSequence(ref command_sequence) => command_sequence
.iter()
.map(|command| command.name().to_string())
.collect::<Vec<_>>()
.join(" → ")
.clone(),
KeyTrieNode::KeyTrie(key_trie) => key_trie.description.clone(),
};
let key_event = key_event_order[index];
match body
Expand Down Expand Up @@ -148,10 +153,11 @@ impl KeyTrie {
body = keyevent_sort_infobox(body);
}

let stringified_key_events_body: Vec<(String, &str)> = body
.iter()
.map(|(key_events, description)| (key_events.join(", "), *description))
.collect();
// TODO: create InfoboxBody collect
let mut stringified_key_events_body = Vec::with_capacity(body.len());
for (key_events, description) in body {
stringified_key_events_body.push((key_events.join(", "), description));
}

Info::new(&self.description, &stringified_key_events_body)
}
Expand Down Expand Up @@ -192,8 +198,8 @@ impl<'de> Deserialize<'de> for KeyTrie {
}

// (KeyEvents, Description)
type InfoBoxRow<'a> = (Vec<String>, &'a str);
type InfoBoxBody<'a> = Vec<InfoBoxRow<'a>>;
type InfoBoxRow = (Vec<String>, String);
type InfoBoxBody = Vec<InfoBoxRow>;
/// Sorts by `ModifierKeyCode`, then by each `KeyCode` category, then by each `KeyEvent`.
/// KeyCode::Char sorting is special in that lower-case and upper-case equivalents are
/// placed together, and alphas are placed before the rest.
Expand Down

0 comments on commit 8dd2169

Please sign in to comment.