From 903b10de9a331d21787c832fa6b91f1cdd7f1f6c Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:26:18 +0000 Subject: [PATCH] fix: always subtract the correct amount --- helix-term/src/commands.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7faa69a8e0ea..1840a3bb9e0f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4070,9 +4070,7 @@ pub mod insert { // Note that `first_trailing_whitespace_char` is at least `pos` so the // unsigned subtraction (`pos - first_trailing_whitespace_char`) cannot // underflow. - local_offs as isize - - (pos + if ranges.is_empty() { 0 } else { 1 } - - first_trailing_whitespace_char) as isize, + local_offs as isize - (pos - first_trailing_whitespace_char) as isize, ) } else { // If the current line is all whitespace, insert a line ending at the beginning of @@ -4083,6 +4081,8 @@ pub mod insert { (line_start, line_start, new_text.chars().count() as isize) }; + let local_offs = local_offs - if ranges.is_empty() { 0 } else { 1 }; + let new_range = if range.cursor(text) > range.anchor { // when appending, extend the range by local_offs Range::new(