summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vegdahl2021-06-23 02:07:19 +0000
committerBlaž Hrastnik2021-06-23 03:43:09 +0000
commit848cc1b438ac75f90e72e35afe66a6e153ced4ac (patch)
tree89381e3334bc28391ac9cf7a5d734a5eb238dbd1
parent481c4ba0440a92a7873c49c37d4b76f90d585599 (diff)
Fix extend_line() behavior.
It would always extend to the next line if the cursor was at the end of the current line, even if the current line wasn't fully selected yet.
-rw-r--r--helix-term/src/commands.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index f8b9e387..8c76e869 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -900,14 +900,13 @@ fn extend_line(cx: &mut Context) {
let text = doc.text();
let line_start = text.char_to_line(pos.anchor);
- let mut line = text.char_to_line(pos.head);
- let line_end = line_end_char_index(&text.slice(..), line);
- if line_start <= pos.anchor && pos.head == line_end && line < (text.len_lines() - 2) {
- line += 1;
- }
-
let start = text.line_to_char(line_start);
- let end = line_end_char_index(&text.slice(..), line);
+ let line_end = text.char_to_line(pos.head);
+ let mut end = line_end_char_index(&text.slice(..), line_end);
+
+ if pos.anchor == start && pos.head == end && line_end < (text.len_lines() - 2) {
+ end = line_end_char_index(&text.slice(..), line_end + 1);
+ }
doc.set_selection(view.id, Selection::single(start, end));
}