feat(term): uniformize word-wise movement and deletion (#2500)

Ctrl-based shortcuts are common in numerous applications.

This change:
- Adds Ctrl+{Left/Right/Backspace/Delete} for word-wise movement/deletion in prompt, picker, …
- Removes Alt-Left and Alt-Right in prompt, picker, …
- Adds Alt-Delete in insert mode for forward word deletion

In some terminals, Alt-Backspace might not work because it is ambigous.
See: https://github.com/helix-editor/helix/pull/2193#issuecomment-1105042501
Hence, Alt alternative is not removed.
pull/2459/head
Benoît Cortier 2 years ago committed by GitHub
parent 8681fb6d9e
commit 333ab27837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -303,8 +303,8 @@ undo-able "save point" until you return to normal mode.
| `Escape` | Switch to normal mode | `normal_mode` | | `Escape` | Switch to normal mode | `normal_mode` |
| `Ctrl-x` | Autocomplete | `completion` | | `Ctrl-x` | Autocomplete | `completion` |
| `Ctrl-r` | Insert a register content | `insert_register` | | `Ctrl-r` | Insert a register content | `insert_register` |
| `Ctrl-w`, `Alt-Backspace` | Delete previous word | `delete_word_backward` | | `Ctrl-w`, `Alt-Backspace`, `Ctrl-Backspace` | Delete previous word | `delete_word_backward` |
| `Alt-d` | Delete next word | `delete_word_forward` | | `Alt-d`, `Alt-Delete`, `Ctrl-Delete` | Delete next word | `delete_word_forward` |
| `Alt-b`, `Ctrl-Left` | Backward a word | `move_prev_word_end` | | `Alt-b`, `Ctrl-Left` | Backward a word | `move_prev_word_end` |
| `Ctrl-b`, `Left` | Backward a char | `move_char_left` | | `Ctrl-b`, `Left` | Backward a char | `move_char_left` |
| `Alt-f`, `Ctrl-Right` | Forward a word | `move_next_word_start` | | `Alt-f`, `Ctrl-Right` | Forward a word | `move_next_word_start` |
@ -361,14 +361,14 @@ Keys to use within prompt, Remapping currently not supported.
| Key | Description | | Key | Description |
| ----- | ------------- | | ----- | ------------- |
| `Escape`, `Ctrl-c` | Close prompt | | `Escape`, `Ctrl-c` | Close prompt |
| `Alt-b`, `Alt-Left` | Backward a word | | `Alt-b`, `Ctrl-Left` | Backward a word |
| `Ctrl-b`, `Left` | Backward a char | | `Ctrl-b`, `Left` | Backward a char |
| `Alt-f`, `Alt-Right` | Forward a word | | `Alt-f`, `Ctrl-Right` | Forward a word |
| `Ctrl-f`, `Right` | Forward a char | | `Ctrl-f`, `Right` | Forward a char |
| `Ctrl-e`, `End` | Move prompt end | | `Ctrl-e`, `End` | Move prompt end |
| `Ctrl-a`, `Home` | Move prompt start | | `Ctrl-a`, `Home` | Move prompt start |
| `Ctrl-w` | Delete previous word | | `Ctrl-w`, `Alt-Backspace`, `Ctrl-Backspace` | Delete previous word |
| `Alt-d` | Delete next word | | `Alt-d`, `Alt-Delete`, `Ctrl-Delete` | Delete next word |
| `Ctrl-u` | Delete to start of line | | `Ctrl-u` | Delete to start of line |
| `Ctrl-k` | Delete to end of line | | `Ctrl-k` | Delete to end of line |
| `backspace`, `Ctrl-h` | Delete previous char | | `backspace`, `Ctrl-h` | Delete previous char |
@ -380,4 +380,3 @@ Keys to use within prompt, Remapping currently not supported.
| `Tab` | Select next completion item | | `Tab` | Select next completion item |
| `BackTab` | Select previous completion item | | `BackTab` | Select previous completion item |
| `Enter` | Open selected | | `Enter` | Open selected |

@ -350,7 +350,7 @@ impl Application {
} }
fn refresh_config(&mut self) { fn refresh_config(&mut self) {
let config = Config::load(helix_loader::config_file()).unwrap_or_else(|err| { let config = Config::load_default().unwrap_or_else(|err| {
self.editor.set_error(err.to_string()); self.editor.set_error(err.to_string());
Config::default() Config::default()
}); });

@ -351,6 +351,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" => delete_word_backward, "C-w" => delete_word_backward,
"A-backspace" => delete_word_backward, "A-backspace" => delete_word_backward,
"A-d" => delete_word_forward, "A-d" => delete_word_forward,
"A-del" => delete_word_forward,
"C-s" => commit_undo_checkpoint, "C-s" => commit_undo_checkpoint,
"left" => move_char_left, "left" => move_char_left,

@ -477,14 +477,14 @@ impl Component for Prompt {
(self.callback_fn)(cx, &self.line, PromptEvent::Abort); (self.callback_fn)(cx, &self.line, PromptEvent::Abort);
return close_fn; return close_fn;
} }
alt!('b') | alt!(Left) => self.move_cursor(Movement::BackwardWord(1)), alt!('b') | ctrl!(Left) => self.move_cursor(Movement::BackwardWord(1)),
alt!('f') | alt!(Right) => self.move_cursor(Movement::ForwardWord(1)), alt!('f') | ctrl!(Right) => self.move_cursor(Movement::ForwardWord(1)),
ctrl!('b') | key!(Left) => self.move_cursor(Movement::BackwardChar(1)), ctrl!('b') | key!(Left) => self.move_cursor(Movement::BackwardChar(1)),
ctrl!('f') | key!(Right) => self.move_cursor(Movement::ForwardChar(1)), ctrl!('f') | key!(Right) => self.move_cursor(Movement::ForwardChar(1)),
ctrl!('e') | key!(End) => self.move_end(), ctrl!('e') | key!(End) => self.move_end(),
ctrl!('a') | key!(Home) => self.move_start(), ctrl!('a') | key!(Home) => self.move_start(),
ctrl!('w') => self.delete_word_backwards(cx), ctrl!('w') | alt!(Backspace) | ctrl!(Backspace) => self.delete_word_backwards(cx),
alt!('d') => self.delete_word_forwards(cx), alt!('d') | alt!(Delete) | ctrl!(Delete) => self.delete_word_forwards(cx),
ctrl!('k') => self.kill_to_end_of_line(cx), ctrl!('k') => self.kill_to_end_of_line(cx),
ctrl!('u') => self.kill_to_start_of_line(cx), ctrl!('u') => self.kill_to_start_of_line(cx),
ctrl!('h') | key!(Backspace) => { ctrl!('h') | key!(Backspace) => {

Loading…
Cancel
Save