From 84a0117cd7624ad3d7c57cb71a07415f8ff335cc Mon Sep 17 00:00:00 2001 From: Waleed Dahshan Date: Sun, 28 Jan 2024 07:40:33 +1100 Subject: [PATCH 1/3] use anchor and head positions to determine motion --- helix-term/src/commands.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4df3278b8bba..f9b292f04b67 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3650,8 +3650,7 @@ pub mod insert { (pos, pos, local_offs) }; - - let new_range = if doc.restore_cursor { + let new_range = if range.head > range.anchor { // when appending, extend the range by local_offs Range::new( range.anchor + global_offs, From 8703ad41df29c9830856421cdf1788cf1b3ba7c5 Mon Sep 17 00:00:00 2001 From: Waleed Dahshan Date: Sun, 28 Jan 2024 09:30:10 +1100 Subject: [PATCH 2/3] use range cursor to decide extending or shifting --- helix-term/src/commands.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f9b292f04b67..d44f477b7376 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3650,7 +3650,8 @@ pub mod insert { (pos, pos, local_offs) }; - let new_range = if range.head > range.anchor { + + let new_range = if range.cursor(text) > range.anchor { // when appending, extend the range by local_offs Range::new( range.anchor + global_offs, From 40f0e0e82a3541d414735f9d7c9ff94beae8f037 Mon Sep 17 00:00:00 2001 From: Waleed Dahshan Date: Tue, 30 Jan 2024 04:02:15 +1100 Subject: [PATCH 3/3] add condition to cursor moving back on normal --- helix-view/src/editor.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index eca488e74002..bcba62ba51d3 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1904,10 +1904,12 @@ impl Editor { if doc.restore_cursor { let text = doc.text().slice(..); let selection = doc.selection(view.id).clone().transform(|range| { - Range::new( - range.from(), - graphemes::prev_grapheme_boundary(text, range.to()), - ) + let mut head = range.to(); + if range.head > range.anchor { + head = graphemes::prev_grapheme_boundary(text, head); + } + + Range::new(range.from(), head) }); doc.set_selection(view.id, selection);