aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/keymap.rs
diff options
context:
space:
mode:
authorGokul Soumya2022-07-02 11:21:27 +0000
committerGitHub2022-07-02 11:21:27 +0000
commit6e2aaed5c2cbcedc9ee4e225510cae4f357888aa (patch)
treebddbecd95c9b3df5cb207736f1d0cbdeb56c1c3c /helix-term/src/keymap.rs
parent290b3ebbbe0c365eee436b9de9d6d6fc2b4339e9 (diff)
Reuse menu::Item trait in picker (#2814)
* Refactor menu::Item to accomodate external state Will be useful for storing editor state when reused by pickers. * Add some type aliases for readability * Reuse menu::Item trait in picker This opens the way for merging the menu and picker code in the future, since a picker is essentially a menu + prompt. More excitingly, this change will also allow aligning items in the picker, which would be useful (for example) in the command palette for aligning the descriptions to the left and the keybinds to the right in two separate columns. The item formatting of each picker has been kept as is, even though there is room for improvement now that we can format the data into columns, since that is better tackled in a separate PR. * Rename menu::Item::EditorData to Data * Call and inline filter_text() in sort_text() completion * Rename diagnostic picker's Item::Data
Diffstat (limited to 'helix-term/src/keymap.rs')
-rw-r--r--helix-term/src/keymap.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index db958833..59204889 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -208,18 +208,17 @@ pub struct Keymap {
root: KeyTrie,
}
+/// A map of command names to keybinds that will execute the command.
+pub type ReverseKeymap = HashMap<String, Vec<Vec<KeyEvent>>>;
+
impl Keymap {
pub fn new(root: KeyTrie) -> Self {
Keymap { root }
}
- pub fn reverse_map(&self) -> HashMap<String, Vec<Vec<KeyEvent>>> {
+ pub fn reverse_map(&self) -> ReverseKeymap {
// recursively visit all nodes in keymap
- fn map_node(
- cmd_map: &mut HashMap<String, Vec<Vec<KeyEvent>>>,
- node: &KeyTrie,
- keys: &mut Vec<KeyEvent>,
- ) {
+ fn map_node(cmd_map: &mut ReverseKeymap, node: &KeyTrie, keys: &mut Vec<KeyEvent>) {
match node {
KeyTrie::Leaf(cmd) => match cmd {
MappableCommand::Typable { name, .. } => {