mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
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.
This commit is contained in:
parent
3a0892f793
commit
19326d23d1
@ -77,7 +77,7 @@ pub fn merge(&mut self, mut other: Self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn infobox(&self) -> Info {
|
pub fn infobox(&self) -> Info {
|
||||||
let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
|
let mut body: Vec<(BTreeSet<KeyEvent>, &str)> = Vec::with_capacity(self.len());
|
||||||
for (&key, trie) in self.iter() {
|
for (&key, trie) in self.iter() {
|
||||||
let desc = match trie {
|
let desc = match trie {
|
||||||
KeyTrie::MappableCommand(cmd) => {
|
KeyTrie::MappableCommand(cmd) => {
|
||||||
@ -89,14 +89,14 @@ pub fn infobox(&self) -> Info {
|
|||||||
KeyTrie::Node(n) => n.name(),
|
KeyTrie::Node(n) => n.name(),
|
||||||
KeyTrie::Sequence(_) => "[Multiple commands]",
|
KeyTrie::Sequence(_) => "[Multiple commands]",
|
||||||
};
|
};
|
||||||
match body.iter().position(|(d, _)| d == &desc) {
|
match body.iter().position(|(_, d)| d == &desc) {
|
||||||
Some(pos) => {
|
Some(pos) => {
|
||||||
body[pos].1.insert(key);
|
body[pos].0.insert(key);
|
||||||
}
|
}
|
||||||
None => body.push((desc, BTreeSet::from([key]))),
|
None => body.push((BTreeSet::from([key]), desc)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body.sort_unstable_by_key(|(_, keys)| {
|
body.sort_unstable_by_key(|(keys, _)| {
|
||||||
self.order
|
self.order
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&k| k == *keys.iter().next().unwrap())
|
.position(|&k| k == *keys.iter().next().unwrap())
|
||||||
|
@ -55,10 +55,10 @@ pub fn new<T, U>(title: &str, body: &[(T, U)]) -> Self
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
|
pub fn from_keymap(title: &str, body: Vec<(BTreeSet<KeyEvent>, &str)>) -> Self {
|
||||||
let body: Vec<_> = body
|
let body: Vec<_> = body
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(desc, events)| {
|
.map(|(events, desc)| {
|
||||||
let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
|
let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
|
||||||
(events.join(", "), desc)
|
(events.join(", "), desc)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user