From 0d1dd4603ee731cbca9e204a9a97df492f6a89b5 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Tue, 9 Nov 2021 15:55:50 +0800 Subject: [PATCH 1/9] readline style insert mode --- book/src/keymap.md | 13 +++++++++++++ helix-term/src/commands.rs | 31 +++++++++++++++++++++++++++++++ helix-term/src/keymap.rs | 16 ++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/book/src/keymap.md b/book/src/keymap.md index 6ae1e8d476fc..3e73855b7a20 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -239,6 +239,19 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire | `Escape` | Switch to normal mode | `normal_mode` | | `Ctrl-x` | Autocomplete | `completion` | | `Ctrl-w` | Delete previous word | `delete_word_backward` | +| `Alt-b`, `Alt-Left` | Backward a word | +| `Ctrl-b`, `Left` | Backward a char | +| `Alt-f`, `Alt-Right` | Forward a word | +| `Ctrl-f`, `Right` | Forward a char | +| `Ctrl-e`, `End` | move to line end | +| `Ctrl-a`, `Home` | move to line start | +| `Ctrl-w` | delete previous word | +| `Ctrl-u` | delete to start of line | +| `Ctrl-k` | delete to end of line | +| `backspace`, `Ctrl-h` | delete previous char | +| `delete`, `Ctrl-d` | delete previous char | +| `Ctrl-p`, `Up` | move to previous line | +| `Ctrl-n`, `Down` | move to next line | ## Select / extend mode diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 42163b8e0ddb..bdb875ad80d3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -185,6 +185,7 @@ impl Command { copy_selection_on_prev_line, "Copy selection on previous line", move_next_word_start, "Move to beginning of next word", move_prev_word_start, "Move to beginning of previous word", + move_prev_word_end, "Move to end of previous word", move_next_word_end, "Move to end of next word", move_next_long_word_start, "Move to beginning of next long word", move_prev_long_word_start, "Move to beginning of previous long word", @@ -279,6 +280,9 @@ impl Command { delete_char_backward, "Delete previous char", delete_char_forward, "Delete next char", delete_word_backward, "Delete previous word", + delete_word_forward, "Delete next word", + kill_to_line_start, "Delete content till the start of the line", + kill_to_line_end, "Delete content till the end of the line", undo, "Undo change", redo, "Redo change", yank, "Yank selection", @@ -563,6 +567,16 @@ fn extend_to_line_start(cx: &mut Context) { goto_line_start_impl(view, doc, Movement::Extend) } +fn kill_to_line_start(cx: &mut Context) { + extend_to_line_start(cx); + delete_selection(cx); +} + +fn kill_to_line_end(cx: &mut Context) { + extend_to_line_end(cx); + delete_selection(cx); +} + fn goto_first_nonwhitespace(cx: &mut Context) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -639,6 +653,10 @@ fn move_prev_word_start(cx: &mut Context) { move_word_impl(cx, movement::move_prev_word_start) } +fn move_prev_word_end(cx: &mut Context) { + move_word_impl(cx, movement::move_prev_word_end) +} + fn move_next_word_end(cx: &mut Context) { move_word_impl(cx, movement::move_next_word_end) } @@ -3802,6 +3820,19 @@ pub mod insert { doc.set_selection(view.id, selection); delete_selection(cx) } + + pub fn delete_word_forward(cx: &mut Context) { + let count = cx.count(); + let (view, doc) = current!(cx.editor); + let text = doc.text().slice(..); + + let selection = doc + .selection(view.id) + .clone() + .transform(|range| movement::move_next_word_start(text, range, count)); + doc.set_selection(view.id, selection); + delete_selection(cx) + } } // Undo / Redo diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index d497401f99f9..f8d70685c402 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -651,19 +651,35 @@ impl Default for Keymaps { "esc" => normal_mode, "backspace" => delete_char_backward, + "C-h" => delete_char_backward, "del" => delete_char_forward, + "C-d" => delete_char_forward, "ret" => insert_newline, "tab" => insert_tab, "C-w" => delete_word_backward, + "A-d" => delete_word_forward, "left" => move_char_left, + "C-b" => move_char_left, "down" => move_line_down, + "C-n" => move_line_down, "up" => move_line_up, + "C-p" => move_line_up, "right" => move_char_right, + "C-f" => move_char_right, + "A-b" => move_prev_word_end, + "A-left" => move_prev_word_end, + "A-f" => move_next_word_start, + "A-right" => move_next_word_start, "pageup" => page_up, "pagedown" => page_down, "home" => goto_line_start, + "C-a" => goto_line_start, "end" => goto_line_end_newline, + "C-e" => goto_line_end_newline, + + "C-k" => kill_to_line_end, + "C-u" => kill_to_line_start, "C-x" => completion, }); From 9e458272b16a7208e398158bd07a7caa08801597 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Tue, 9 Nov 2021 16:24:59 +0800 Subject: [PATCH 2/9] update keymap.md --- book/src/keymap.md | 38 +++++++++++++++++++------------------ helix-term/src/ui/prompt.rs | 12 ++++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index 3e73855b7a20..05f71d3a6498 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -234,24 +234,25 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire ## Insert Mode -| Key | Description | Command | -| ----- | ----------- | ------- | -| `Escape` | Switch to normal mode | `normal_mode` | -| `Ctrl-x` | Autocomplete | `completion` | -| `Ctrl-w` | Delete previous word | `delete_word_backward` | -| `Alt-b`, `Alt-Left` | Backward a word | -| `Ctrl-b`, `Left` | Backward a char | -| `Alt-f`, `Alt-Right` | Forward a word | -| `Ctrl-f`, `Right` | Forward a char | -| `Ctrl-e`, `End` | move to line end | -| `Ctrl-a`, `Home` | move to line start | -| `Ctrl-w` | delete previous word | -| `Ctrl-u` | delete to start of line | -| `Ctrl-k` | delete to end of line | -| `backspace`, `Ctrl-h` | delete previous char | -| `delete`, `Ctrl-d` | delete previous char | -| `Ctrl-p`, `Up` | move to previous line | -| `Ctrl-n`, `Down` | move to next line | +| Key | Description | Command | +| ----- | ----------- | ------- | +| `Escape` | Switch to normal mode | `normal_mode` | +| `Ctrl-x` | Autocomplete | `completion` | +| `Ctrl-w` | Delete previous word | `delete_word_backward` | +| `Alt-d` | Delete next word | `delete_word_forward` | +| `Alt-b`, `Alt-Left` | Backward a word | `move_prev_word_end` | +| `Ctrl-b`, `Left` | Backward a char | `move_char_left` | +| `Alt-f`, `Alt-Right` | Forward a word | `move_next_word_start` | +| `Ctrl-f`, `Right` | Forward a char | `move_char_right` | +| `Ctrl-e`, `End` | move to line end | `goto_line_end_newline` | +| `Ctrl-a`, `Home` | move to line start | `goto_line_start` | +| `Ctrl-w` | delete previous word | `delete_word_backwar` | +| `Ctrl-u` | delete to start of line | `kill_to_line_start` | +| `Ctrl-k` | delete to end of line | `kill_to_line_end` | +| `backspace`, `Ctrl-h` | delete previous char | `delete_char_backward` | +| `delete`, `Ctrl-d` | delete previous char | `delete_char_forward` | +| `Ctrl-p`, `Up` | move to previous line | `move_line_up` | +| `Ctrl-n`, `Down` | move to next line | `move_line_down` | ## Select / extend mode @@ -287,6 +288,7 @@ Keys to use within prompt, Remapping currently not supported. | `Ctrl-e`, `End` | move prompt end | | `Ctrl-a`, `Home` | move prompt start | | `Ctrl-w` | delete previous word | +| `Alt-d` | delete next word | | `Ctrl-u` | delete to start of line | | `Ctrl-k` | delete to end of line | | `backspace`, `Ctrl-h` | delete previous char | diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 22e4adb8ac5a..302b70badb5f 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -229,6 +229,14 @@ impl Prompt { self.completion = (self.completion_fn)(&self.line); } + pub fn delete_word_forwards(&mut self) { + let pos = self.eval_movement(Movement::ForwardWord(1)); + self.line.replace_range(self.cursor..pos, ""); + + self.exit_selection(); + self.completion = (self.completion_fn)(&self.line); + } + pub fn kill_to_start_of_line(&mut self) { let pos = self.eval_movement(Movement::StartOfLine); self.line.replace_range(pos..self.cursor, ""); @@ -484,6 +492,10 @@ impl Component for Prompt { code: KeyCode::Char('w'), modifiers: KeyModifiers::CONTROL, } => self.delete_word_backwards(), + KeyEvent { + code: KeyCode::Char('d'), + modifiers: KeyModifiers::ALT, + } => self.delete_word_forwards(), KeyEvent { code: KeyCode::Char('k'), modifiers: KeyModifiers::CONTROL, From cb47f946d7fb62ceda68e7d1692a3914d0be7762 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Wed, 10 Nov 2021 10:22:49 +0800 Subject: [PATCH 3/9] don't save change history in insert mode --- helix-term/src/commands.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7d2cd67e2af8..c9a4ea2d4eba 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -569,12 +569,12 @@ fn extend_to_line_start(cx: &mut Context) { fn kill_to_line_start(cx: &mut Context) { extend_to_line_start(cx); - delete_selection(cx); + delete_selection_and_append_history(cx, false); } fn kill_to_line_end(cx: &mut Context) { extend_to_line_end(cx); - delete_selection(cx); + delete_selection_and_append_history(cx, false); } fn goto_first_nonwhitespace(cx: &mut Context) { @@ -1560,13 +1560,19 @@ fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId } fn delete_selection(cx: &mut Context) { + delete_selection_and_append_history(cx, true); +} + +fn delete_selection_and_append_history(cx: &mut Context, append_change_to_history: bool) { let reg_name = cx.register.unwrap_or('"'); let (view, doc) = current!(cx.editor); let registers = &mut cx.editor.registers; let reg = registers.get_mut(reg_name); delete_selection_impl(reg, doc, view.id); - doc.append_changes_to_history(view.id); + if append_change_to_history { + doc.append_changes_to_history(view.id); + } // exit select mode, if currently in select mode exit_select_mode(cx); @@ -3861,7 +3867,7 @@ pub mod insert { .clone() .transform(|range| movement::move_next_word_start(text, range, count)); doc.set_selection(view.id, selection); - delete_selection(cx) + delete_selection_and_append_history(cx, false) } } From 3b9dc0cee4c8f5c0aca319e4397af57528b3b868 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Wed, 10 Nov 2021 10:26:56 +0800 Subject: [PATCH 4/9] Revert "don't save change history in insert mode" This reverts commit cb47f946d7fb62ceda68e7d1692a3914d0be7762. --- helix-term/src/commands.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c9a4ea2d4eba..7d2cd67e2af8 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -569,12 +569,12 @@ fn extend_to_line_start(cx: &mut Context) { fn kill_to_line_start(cx: &mut Context) { extend_to_line_start(cx); - delete_selection_and_append_history(cx, false); + delete_selection(cx); } fn kill_to_line_end(cx: &mut Context) { extend_to_line_end(cx); - delete_selection_and_append_history(cx, false); + delete_selection(cx); } fn goto_first_nonwhitespace(cx: &mut Context) { @@ -1560,19 +1560,13 @@ fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId } fn delete_selection(cx: &mut Context) { - delete_selection_and_append_history(cx, true); -} - -fn delete_selection_and_append_history(cx: &mut Context, append_change_to_history: bool) { let reg_name = cx.register.unwrap_or('"'); let (view, doc) = current!(cx.editor); let registers = &mut cx.editor.registers; let reg = registers.get_mut(reg_name); delete_selection_impl(reg, doc, view.id); - if append_change_to_history { - doc.append_changes_to_history(view.id); - } + doc.append_changes_to_history(view.id); // exit select mode, if currently in select mode exit_select_mode(cx); @@ -3867,7 +3861,7 @@ pub mod insert { .clone() .transform(|range| movement::move_next_word_start(text, range, count)); doc.set_selection(view.id, selection); - delete_selection_and_append_history(cx, false) + delete_selection(cx) } } From 44601d40f2fa2b0fbac7c2d67dda576e337f27b3 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Wed, 10 Nov 2021 10:41:07 +0800 Subject: [PATCH 5/9] don't affect register and history in insert mode --- helix-term/src/commands.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7d2cd67e2af8..4a531feea710 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -569,12 +569,12 @@ fn extend_to_line_start(cx: &mut Context) { fn kill_to_line_start(cx: &mut Context) { extend_to_line_start(cx); - delete_selection(cx); + delete_selection_insert_mode(cx); } fn kill_to_line_end(cx: &mut Context) { extend_to_line_end(cx); - delete_selection(cx); + delete_selection_insert_mode(cx); } fn goto_first_nonwhitespace(cx: &mut Context) { @@ -1559,6 +1559,21 @@ fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId doc.apply(&transaction, view_id); } +fn delete_selection_insert_mode(cx: &mut Context) { + let (view, doc) = current!(cx.editor); + let view_id = view.id; + let selection = doc.selection(view_id); + + // then delete + let transaction = Transaction::change_by_selection(doc.text(), selection, |range| { + (range.from(), range.to(), None) + }); + doc.apply(&transaction, view_id); + + // exit select mode, if currently in select mode + exit_select_mode(cx); +} + fn delete_selection(cx: &mut Context) { let reg_name = cx.register.unwrap_or('"'); let (view, doc) = current!(cx.editor); @@ -3848,7 +3863,7 @@ pub mod insert { .clone() .transform(|range| movement::move_prev_word_start(text, range, count)); doc.set_selection(view.id, selection); - delete_selection(cx) + delete_selection_insert_mode(cx) } pub fn delete_word_forward(cx: &mut Context) { @@ -3861,7 +3876,7 @@ pub mod insert { .clone() .transform(|range| movement::move_next_word_start(text, range, count)); doc.set_selection(view.id, selection); - delete_selection(cx) + delete_selection_insert_mode(cx) } } From 9fb0d4056bad9b95658a8e30b5425381b3468099 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Wed, 10 Nov 2021 11:16:14 +0800 Subject: [PATCH 6/9] add insert_register --- book/src/keymap.md | 25 ++++++++++++++++++++----- helix-term/src/commands.rs | 10 ++++++++++ helix-term/src/keymap.rs | 1 + 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index 65718655a018..57a713e99ddf 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -235,11 +235,26 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire ## Insert Mode -| Key | Description | Command | -| ----- | ----------- | ------- | -| `Escape` | Switch to normal mode | `normal_mode` | -| `Ctrl-x` | Autocomplete | `completion` | -| `Ctrl-w` | Delete previous word | `delete_word_backward` | +| Key | Description | Command | +| ----- | ----------- | ------- | +| `Escape` | Switch to normal mode | `normal_mode` | +| `Ctrl-x` | Autocomplete | `completion` | +| `Ctrl-r` | Insert a register content | `insert_register` | +| `Ctrl-w` | Delete previous word | `delete_word_backward` | +| `Alt-d` | Delete next word | `delete_word_forward` | +| `Alt-b`, `Alt-Left` | Backward a word | `move_prev_word_end` | +| `Ctrl-b`, `Left` | Backward a char | `move_char_left` | +| `Alt-f`, `Alt-Right` | Forward a word | `move_next_word_start` | +| `Ctrl-f`, `Right` | Forward a char | `move_char_right` | +| `Ctrl-e`, `End` | move to line end | `goto_line_end_newline` | +| `Ctrl-a`, `Home` | move to line start | `goto_line_start` | +| `Ctrl-w` | delete previous word | `delete_word_backwar` | +| `Ctrl-u` | delete to start of line | `kill_to_line_start` | +| `Ctrl-k` | delete to end of line | `kill_to_line_end` | +| `backspace`, `Ctrl-h` | delete previous char | `delete_char_backward` | +| `delete`, `Ctrl-d` | delete previous char | `delete_char_forward` | +| `Ctrl-p`, `Up` | move to previous line | `move_line_up` | +| `Ctrl-n`, `Down` | move to next line | `move_line_down` | ## Select / extend mode diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4a531feea710..219019df7c74 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -325,6 +325,7 @@ impl Command { vsplit, "Vertical right split", wclose, "Close window", select_register, "Select register", + insert_register, "Insert register", align_view_middle, "Align view middle", align_view_top, "Align view top", align_view_center, "Align view center", @@ -4777,6 +4778,15 @@ fn select_register(cx: &mut Context) { }) } +fn insert_register(cx: &mut Context) { + cx.on_next_key(move |cx, event| { + if let Some(ch) = event.char() { + cx.editor.selected_register = Some(ch); + paste_before(cx); + } + }) +} + fn align_view_top(cx: &mut Context) { let (view, doc) = current!(cx.editor); align_view(doc, view, Align::Top); diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index f8d70685c402..5c00ecba78ff 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -682,6 +682,7 @@ impl Default for Keymaps { "C-u" => kill_to_line_start, "C-x" => completion, + "C-r" => insert_register, }); Keymaps(hashmap!( Mode::Normal => Keymap::new(normal), From b521c04a4231999fff1333fde86394de1942593a Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Thu, 11 Nov 2021 09:21:13 +0800 Subject: [PATCH 7/9] don't call exit_select_mode in insert mode --- helix-term/src/commands.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 219019df7c74..8299adc5da2b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1570,9 +1570,6 @@ fn delete_selection_insert_mode(cx: &mut Context) { (range.from(), range.to(), None) }); doc.apply(&transaction, view_id); - - // exit select mode, if currently in select mode - exit_select_mode(cx); } fn delete_selection(cx: &mut Context) { From 69e0f8f51afb02822c2f1a94231f21f822db681c Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Mon, 15 Nov 2021 09:27:22 +0800 Subject: [PATCH 8/9] avoid set_selection --- helix-term/src/commands.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8299adc5da2b..b5316851e3de 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -569,13 +569,26 @@ fn extend_to_line_start(cx: &mut Context) { } fn kill_to_line_start(cx: &mut Context) { - extend_to_line_start(cx); - delete_selection_insert_mode(cx); + let (view, doc) = current!(cx.editor); + let text = doc.text().slice(..); + + let selection = doc.selection(view.id).clone().transform(|range| { + let line = range.cursor_line(text); + range.put_cursor(text, text.line_to_char(line), true) + }); + delete_selection_insert_mode(cx, &selection); } fn kill_to_line_end(cx: &mut Context) { - extend_to_line_end(cx); - delete_selection_insert_mode(cx); + let (view, doc) = current!(cx.editor); + let text = doc.text().slice(..); + + let selection = doc.selection(view.id).clone().transform(|range| { + let line = range.cursor_line(text); + let pos = line_end_char_index(&text, line); + range.put_cursor(text, pos, true) + }); + delete_selection_insert_mode(cx, &selection); } fn goto_first_nonwhitespace(cx: &mut Context) { @@ -1560,10 +1573,10 @@ fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId doc.apply(&transaction, view_id); } -fn delete_selection_insert_mode(cx: &mut Context) { +#[inline] +fn delete_selection_insert_mode(cx: &mut Context, selection: &Selection) { let (view, doc) = current!(cx.editor); let view_id = view.id; - let selection = doc.selection(view_id); // then delete let transaction = Transaction::change_by_selection(doc.text(), selection, |range| { @@ -3860,8 +3873,7 @@ pub mod insert { .selection(view.id) .clone() .transform(|range| movement::move_prev_word_start(text, range, count)); - doc.set_selection(view.id, selection); - delete_selection_insert_mode(cx) + delete_selection_insert_mode(cx, &selection); } pub fn delete_word_forward(cx: &mut Context) { @@ -3873,8 +3885,7 @@ pub mod insert { .selection(view.id) .clone() .transform(|range| movement::move_next_word_start(text, range, count)); - doc.set_selection(view.id, selection); - delete_selection_insert_mode(cx) + delete_selection_insert_mode(cx, &selection); } } From 8569dcf4b72c3bb81f9ca90c5e3b3e3643d34295 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Mon, 15 Nov 2021 11:12:46 +0800 Subject: [PATCH 9/9] avoid duplicated current! --- helix-term/src/commands.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b5316851e3de..6bb42255bcfe 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -576,7 +576,7 @@ fn kill_to_line_start(cx: &mut Context) { let line = range.cursor_line(text); range.put_cursor(text, text.line_to_char(line), true) }); - delete_selection_insert_mode(cx, &selection); + delete_selection_insert_mode(doc, view, &selection); } fn kill_to_line_end(cx: &mut Context) { @@ -588,7 +588,7 @@ fn kill_to_line_end(cx: &mut Context) { let pos = line_end_char_index(&text, line); range.put_cursor(text, pos, true) }); - delete_selection_insert_mode(cx, &selection); + delete_selection_insert_mode(doc, view, &selection); } fn goto_first_nonwhitespace(cx: &mut Context) { @@ -1574,8 +1574,7 @@ fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId } #[inline] -fn delete_selection_insert_mode(cx: &mut Context, selection: &Selection) { - let (view, doc) = current!(cx.editor); +fn delete_selection_insert_mode(doc: &mut Document, view: &View, selection: &Selection) { let view_id = view.id; // then delete @@ -3873,7 +3872,7 @@ pub mod insert { .selection(view.id) .clone() .transform(|range| movement::move_prev_word_start(text, range, count)); - delete_selection_insert_mode(cx, &selection); + delete_selection_insert_mode(doc, view, &selection); } pub fn delete_word_forward(cx: &mut Context) { @@ -3885,7 +3884,7 @@ pub mod insert { .selection(view.id) .clone() .transform(|range| movement::move_next_word_start(text, range, count)); - delete_selection_insert_mode(cx, &selection); + delete_selection_insert_mode(doc, view, &selection); } }