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

Labels for macro commands #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ mod tests {
o = { label = "Edit Config", command = ":open ~/.config" }
c = ":buffer-close"
h = ["vsplit", "normal_mode", "swap_view_left"]
j = {command = ["hsplit", "normal_mode", {}], label = "split down"}
j = {command = ["hsplit", "normal_mode", "swap_view_down"], label = "split down"}
n = { label = "Delete word", command = "@wd" }
"#;

let config = Config::load_test(sample_keymaps);
Expand Down Expand Up @@ -277,6 +278,20 @@ mod tests {
]
);
}

let macro_keys = node.get(&KeyEvent::from_str("n").unwrap()).unwrap();
if let keymap::KeyTrie::MappableCommand(MappableCommand::Macro { name, keys }) =
macro_keys
{
assert_eq!(name, "Delete word");
assert_eq!(
keys,
&vec![
KeyEvent::from_str("w").unwrap(),
KeyEvent::from_str("d").unwrap()
]
);
}
} else {
panic!("Config did not parse to trie");
}
Expand Down
9 changes: 9 additions & 0 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
doc: label,
}))
}

// To label/name macro commands from config
Some(MappableCommand::Macro { keys, .. }) if !label.is_empty() => {
Ok(KeyTrie::MappableCommand(MappableCommand::Macro {
keys,
name: label
}))
}

Some(command) => Ok(KeyTrie::MappableCommand(command)),
}
Some(commands) => {
Expand Down