aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/comment.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/comment.rs')
-rw-r--r--helix-core/src/comment.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs
index fadd88e0..6fc1234d 100644
--- a/helix-core/src/comment.rs
+++ b/helix-core/src/comment.rs
@@ -64,8 +64,10 @@ pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&st
let mut min_next_line = 0;
for selection in selection {
- let start = text.char_to_line(selection.from()).max(min_next_line);
- let end = text.char_to_line(selection.to()) + 1;
+ let (start, end) = selection.line_range(text);
+ let start = start.max(min_next_line).min(text.len_lines());
+ let end = (end + 1).min(text.len_lines());
+
lines.extend(start..end);
min_next_line = end + 1;
}