on master help sign in
Keymap infobox: Idiomatic body tuple.

Does not change any behavior other than making the tuple slightly more idiomatic. Keymap infobox shows key events, then the respective description. This commit makes sure that order is used from the get go, rather than flipping it midway.

commit19326d23d15f5e7a1df61249d071e835a28905ed authorgibbz00 <gabrielhansson00@gmail.com> dateMon 29 May 2023, 22:01 (3 years ago) parent3a0892f
2 files changed+7−7
helix-term/src/keymap.rs+5−5 helix-view/src/info.rs+2−2
helix-term/src/keymap.rs+5−5
@@ -77,7 +77,7 @@ impl KeyTrieNode {
7777 }
7878
7979 pub fn infobox(&self) -> Info {
80− let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
80+ let mut body: Vec<(BTreeSet<KeyEvent>, &str)> = Vec::with_capacity(self.len());
8181 for (&key, trie) in self.iter() {
8282 let desc = match trie {
8383 KeyTrie::MappableCommand(cmd) => {
@@ -89,14 +89,14 @@ impl KeyTrieNode {
8989 KeyTrie::Node(n) => n.name(),
9090 KeyTrie::Sequence(_) => "[Multiple commands]",
9191 };
92− match body.iter().position(|(d, _)| d == &desc) {
92+ match body.iter().position(|(_, d)| d == &desc) {
9393 Some(pos) => {
94− body[pos].1.insert(key);
94+ body[pos].0.insert(key);
9595 }
96− None => body.push((desc, BTreeSet::from([key]))),
96+ None => body.push((BTreeSet::from([key]), desc)),
9797 }
9898 }
99− body.sort_unstable_by_key(|(_, keys)| {
99+ body.sort_unstable_by_key(|(keys, _)| {
100100 self.order
101101 .iter()
102102 .position(|&k| k == *keys.iter().next().unwrap())
helix-view/src/info.rs+2−2
@@ -55,10 +55,10 @@ impl Info {
5555 }
5656 }
5757
58− pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
58+ pub fn from_keymap(title: &str, body: Vec<(BTreeSet<KeyEvent>, &str)>) -> Self {
5959 let body: Vec<_> = body
6060 .into_iter()
61− .map(|(desc, events)| {
61+ .map(|(events, desc)| {
6262 let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
6363 (events.join(", "), desc)
6464 })