Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate Key Remapping #3130

Closed
GreasySlug opened this issue Jul 21, 2022 · 1 comment
Closed

Annotate Key Remapping #3130

GreasySlug opened this issue Jul 21, 2022 · 1 comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements

Comments

@GreasySlug
Copy link
Contributor

Describe your feature request

Suppose you have created a new keymap in your user settings.
e.g.

[keys.insert]
j = { j = "normal_mode", s = ":write" , C-s = [":write", ":format"] }

then, the infobox displays like this

+--------------------------+
| j Enter normal mode |
| C-s [Multiple commands] |
| s :write[] |
+--------------------------+

I want the it to be displayed like this

+-------------------------+
| j Enter normal mode |
| C-s write and format |
| s write |
+-------------------------+

If you don't annotate anything, it will display as before.
If annotated, override the infobox.

pub fn infobox(&self) -> Info {
let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
for (&key, trie) in self.iter() {
let desc = match trie {
KeyTrie::Leaf(cmd) => {
if cmd.name() == "no_op" {
continue;
}
cmd.doc()
}
KeyTrie::Node(n) => n.name(),
KeyTrie::Sequence(_) => "[Multiple commands]",
};
match body.iter().position(|(d, _)| d == &desc) {
Some(pos) => {
body[pos].1.insert(key);
}
None => body.push((desc, BTreeSet::from([key]))),
}
}
body.sort_unstable_by_key(|(_, keys)| {
self.order
.iter()
.position(|&k| k == *keys.iter().next().unwrap())
.unwrap()
});
let prefix = format!("{} ", self.name());
if body.iter().all(|(desc, _)| desc.starts_with(&prefix)) {
body = body
.into_iter()
.map(|(desc, keys)| (desc.strip_prefix(&prefix).unwrap(), keys))
.collect();
}
Info::from_keymap(self.name(), body)
}
/// Get a reference to the key trie node's order.
pub fn order(&self) -> &[KeyEvent] {
self.order.as_slice()
}
}

static_commands!(

@GreasySlug GreasySlug added the C-enhancement Category: Improvements label Jul 21, 2022
@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Jul 26, 2022
@kirawi
Copy link
Member

kirawi commented Nov 10, 2022

This seems to actually be a duplicate of #1487 and #1752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

3 participants