From 848cc1b438ac75f90e72e35afe66a6e153ced4ac Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Tue, 22 Jun 2021 19:07:19 -0700 Subject: [PATCH] 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. --- helix-term/src/commands.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f8b9e387f..8c76e869f 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)); }