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

Configurable keymap ordering. #7216

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions book/src/remapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ c = ":run-shell-command cargo build"
t = ":run-shell-command cargo test"
```

## Info box ordering

Order of keybindings in config is preserved when displaying the respective info
boxes. User defined keybindings take precedence over the built-in bindings,
meaning that they are shown first.

## Special keys and modifiers

Ctrl, Shift and Alt modifiers are encoded respectively with the prefixes
Expand Down
31 changes: 25 additions & 6 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ impl Config {
(Ok(global), Ok(local)) => {
let mut keys = keymap::default();
if let Some(global_keys) = global.keys {
merge_keys(&mut keys, global_keys)
keys = merge_keys(keys, global_keys)
}
if let Some(local_keys) = local.keys {
merge_keys(&mut keys, local_keys)
keys = merge_keys(keys, local_keys)
}

let editor = match (global.editor, local.editor) {
Expand All @@ -98,7 +98,7 @@ impl Config {
(Ok(config), Err(_)) | (Err(_), Ok(config)) => {
let mut keys = keymap::default();
if let Some(keymap) = config.keys {
merge_keys(&mut keys, keymap);
keys = merge_keys(keys, keymap);
}
Config {
theme: config.theme,
Expand Down Expand Up @@ -150,9 +150,8 @@ mod tests {
A-F12 = "move_next_word_end"
"#;

let mut keys = keymap::default();
merge_keys(
&mut keys,
let keys = merge_keys(
keymap::default(),
hashmap! {
Mode::Insert => keymap!({ "Insert mode"
"y" => move_line_down,
Expand All @@ -173,6 +172,26 @@ mod tests {
);
}

#[test]
fn keybinding_order_preservation() {
let keymap = r#"
[keys.insert]
y = "move_line_down"
S-C-a = "delete_selection"
"#;

let reversed_keymap = r#"
[keys.insert]
S-C-a = "delete_selection"
y = "move_line_down"
"#;

assert_ne!(
Config::load_test(keymap),
Config::load_test(reversed_keymap)
)
}

#[test]
fn keys_resolve_to_correct_defaults() {
// From serde default
Expand Down
Loading