Skip to content

Commit

Permalink
Add disambiguated keycodes to default keymaps
Browse files Browse the repository at this point in the history
With the enhanced keyboard protocol enabled, some additional key
combinations must be added to the defaults. Mostly this involves
combinations that couldn't be disambiguated without the enhanced
keyboard protocol like 'S-backspace'.

Some other key combinations change the way that the KeyEvent is
structured. For example, `A-_` becomes `A-S-minus`.

Co-authored-by: lesleyrs <19632758+lesleyrs@users.noreply.github.com>
  • Loading branch information
the-mikedavis and lesleyrs committed Feb 7, 2023
1 parent 59c6e6e commit 88d1efa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ experience.
| `Alt-d`, `Alt-Delete` | Delete next word | `delete_word_forward` |
| `Ctrl-u` | Delete to start of line | `kill_to_line_start` |
| `Ctrl-k` | Delete to end of line | `kill_to_line_end` |
| `Ctrl-h`, `Backspace` | Delete previous char | `delete_char_backward` |
| `Ctrl-h`, `Backspace`, `Shift-Backspace` | Delete previous char | `delete_char_backward` |
| `Ctrl-d`, `Delete` | Delete next char | `delete_char_forward` |
| `Ctrl-j`, `Enter` | Insert new line | `insert_newline` |

Expand Down Expand Up @@ -431,7 +431,7 @@ Keys to use within prompt, Remapping currently not supported.
| `Alt-d`, `Alt-Delete`, `Ctrl-Delete` | Delete next word |
| `Ctrl-u` | Delete to start of line |
| `Ctrl-k` | Delete to end of line |
| `Backspace`, `Ctrl-h` | Delete previous char |
| `Backspace`, `Ctrl-h`, `Shift-Backspace` | Delete previous char |
| `Delete`, `Ctrl-d` | Delete next char |
| `Ctrl-s` | Insert a word under doc cursor, may be changed to Ctrl-r Ctrl-w later |
| `Ctrl-p`, `Up` | Select previous history |
Expand Down
10 changes: 5 additions & 5 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn default() -> HashMap<Mode, Keymap> {

"s" => select_regex,
"A-s" => split_selection_on_newline,
"A-_" => merge_consecutive_selections,
"A-_" | "A-S-minus" => merge_consecutive_selections,
"S" => split_selection,
";" => collapse_selection,
"A-;" => flip_selections,
Expand Down Expand Up @@ -167,8 +167,8 @@ pub fn default() -> HashMap<Mode, Keymap> {

"(" => rotate_selections_backward,
")" => rotate_selections_forward,
"A-(" => rotate_selection_contents_backward,
"A-)" => rotate_selection_contents_forward,
"A-(" | "A-S-9" => rotate_selection_contents_backward,
"A-)" | "A-S-0" => rotate_selection_contents_forward,

"A-:" => ensure_selections_forward,

Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"|" => shell_pipe,
"A-|" => shell_pipe_to,
"!" => shell_insert_output,
"A-!" => shell_append_output,
"A-!" | "A-S-1" => shell_append_output,
"$" => shell_keep_pipe,
"C-z" => suspend,

Expand Down Expand Up @@ -363,7 +363,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"A-d" | "A-del" => delete_word_forward,
"C-u" => kill_to_line_start,
"C-k" => kill_to_line_end,
"C-h" | "backspace" => delete_char_backward,
"C-h" | "backspace" | "S-backspace" => delete_char_backward,
"C-d" | "del" => delete_char_forward,
"C-j" | "ret" => insert_newline,
"tab" => insert_tab,
Expand Down
12 changes: 6 additions & 6 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,11 +1447,11 @@ impl Component for EditorView {
}

fn canonicalize_key(key: &mut KeyEvent) {
if let KeyEvent {
code: KeyCode::Char(_),
modifiers: _,
} = key
{
key.modifiers.remove(KeyModifiers::SHIFT)
match key {
KeyEvent {
code: KeyCode::Char(char),
modifiers: _,
} if char.is_alphabetic() => key.modifiers.remove(KeyModifiers::SHIFT),
_ => (),
}
}
2 changes: 1 addition & 1 deletion helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl Component for Prompt {
alt!('d') | alt!(Delete) | ctrl!(Delete) => self.delete_word_forwards(cx.editor),
ctrl!('k') => self.kill_to_end_of_line(cx.editor),
ctrl!('u') => self.kill_to_start_of_line(cx.editor),
ctrl!('h') | key!(Backspace) => {
ctrl!('h') | key!(Backspace) | shift!(Backspace) => {
self.delete_char_backwards(cx.editor);
(self.callback_fn)(cx, &self.line, PromptEvent::Update);
}
Expand Down

0 comments on commit 88d1efa

Please sign in to comment.