on master help sign in
Fix comment toggle command also sometimes toggling the next line.
commitc9300ec35f1baeab92a5375814b91bb81c66de73 authorNathan Vegdahl <cessen@cessen.com> dateTue 20 Jul 2021, 12:23 (5 years ago) parent1c6b558
2 files changed+15−2
helix-core/src/comment.rs+1−2 helix-core/src/selection.rs+14
helix-core/src/comment.rs+1−2
@@ -46,8 +46,7 @@ pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&st
4646 let comment = Tendril::from(format!("{} ", token));
4747
4848 for selection in selection {
49− let start = text.char_to_line(selection.from());
50− let end = text.char_to_line(selection.to());
49+ let (start, end) = selection.line_range(text);
5150 let lines = start..end + 1;
5251 let (commented, skipped, min) = find_line_comment(&token, text, lines.clone());
5352
helix-core/src/selection.rs+14
@@ -73,6 +73,20 @@ impl Range {
7373 std::cmp::max(self.anchor, self.head)
7474 }
7575
76+ /// The (inclusive) range of lines that the range overlaps.
77+ #[inline]
78+ #[must_use]
79+ pub fn line_range(&self, text: RopeSlice) -> (usize, usize) {
80+ let from = self.from();
81+ let to = if self.is_empty() {
82+ self.to()
83+ } else {
84+ prev_grapheme_boundary(text, self.to()).max(from)
85+ };
86+
87+ (text.char_to_line(from), text.char_to_line(to))
88+ }
89+
7690 /// `true` when head and anchor are at the same position.
7791 #[inline]
7892 pub fn is_empty(&self) -> bool {