From 7a39fb816436c9dcaaf48ce32242a3dcefd8a52b Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sun, 2 Feb 2025 18:09:57 +0000 Subject: [PATCH] refactor: rename variable --- helix-core/src/comment.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs index e5a17a79d..26ab4f31f 100644 --- a/helix-core/src/comment.rs +++ b/helix-core/src/comment.rs @@ -310,14 +310,32 @@ pub fn toggle_block_comments( // every 2 elements (from, to) in `changes` corresponds // the `from` - `to` represents the range of text that will be deleted. // to 1 element in `new_ranges` - let (from, to, _) = changes[i * 2]; - let (from2, to2, _) = changes[i * 2 + 1]; - *added_chars -= to as isize - from as isize; + // + // Left token: + // + // "" + // ^ right_from + // ^ right_o + let (left_from, left_to, _) = changes[i * 2]; + let (right_from, right_o, _) = changes[i * 2 + 1]; + + *added_chars -= left_to as isize - left_from as isize; + + // We slide the range to the left by the amount of characters + // we've deleted so far + the amount of chars deleted for + // the left comment token of the current iteration selections.push(Range::new( (range.anchor as isize + *added_chars).try_into().unwrap(), (range.head as isize + *added_chars).try_into().unwrap(), )); - *added_chars -= to2 as isize - from2 as isize; + + *added_chars -= right_o as isize - right_from as isize; } changes