aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorIvan Tham2022-05-11 01:12:27 +0000
committerGitHub2022-05-11 01:12:27 +0000
commit0477d0289476c34e6b4d11a28165fee0c49063b3 (patch)
tree63db7b95e834f28d2e21dcaed70933a2221e65d8 /helix-term/src
parentc80ac84978fa224498aaae86e2434b568221d216 (diff)
Exclude cursor when doing ctrl-w (#2431)
Currently ctrl-w in insert mode deletes the cursor which results in unexpected behavior. The patch also reduces the selection to cursor before performing prev word to remove the behavior of removing unnecessary text when nothing should be removed. 1. `::#(|)#::` after `ctrl-w` should be `#(|)#::`, previously `#(|)#:` 2. `#(|::)#` after `ctrl-w` should be `#(|::)#`, previously `#(|)#` Fix #2390
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c2bc04e0..f0b54e0b 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2632,6 +2632,18 @@ pub mod insert {
pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
pub type PostHook = fn(&mut Context, char);
+ /// Exclude the cursor in range.
+ fn exclude_cursor(text: RopeSlice, range: Range, cursor: Range) -> Range {
+ if range.to() == cursor.to() {
+ Range::new(
+ range.from(),
+ graphemes::prev_grapheme_boundary(text, cursor.to()),
+ )
+ } else {
+ range
+ }
+ }
+
// It trigger completion when idle timer reaches deadline
// Only trigger completion if the word under cursor is longer than n characters
pub fn idle_completion(cx: &mut Context) {
@@ -2948,10 +2960,11 @@ pub mod insert {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
- let selection = doc
- .selection(view.id)
- .clone()
- .transform(|range| movement::move_prev_word_start(text, range, count));
+ let selection = doc.selection(view.id).clone().transform(|range| {
+ let cursor = Range::point(range.cursor(text));
+ let next = movement::move_prev_word_start(text, cursor, count);
+ exclude_cursor(text, next, range)
+ });
delete_selection_insert_mode(doc, view, &selection);
}