From c2fd55e1685d22de2facf5acbfe6b7ddc02c7c84 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 17 Jul 2021 11:28:20 -0700 Subject: Update extend_line command to work with gap indexing. --- helix-term/src/commands.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ae71b701..41b342b2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1100,16 +1100,18 @@ fn extend_line(cx: &mut Context) { let count = cx.count(); let (view, doc) = current!(cx.editor); - let pos = doc.selection(view.id).primary(); let text = doc.text(); + let pos = doc.selection(view.id).primary().min_width_1(text.slice(..)); - let line_start = text.char_to_line(pos.anchor); - let start = text.line_to_char(line_start); - let line_end = text.char_to_line(pos.head); - let mut end = line_end_char_index(&text.slice(..), line_end + count.saturating_sub(1)); + let line_max = text.len_lines(); + let start_line = text.char_to_line(pos.from()).min(line_max); + let end_line = (text.char_to_line(pos.to()) + count).min(line_max); - if pos.anchor == start && pos.head == end && line_end < (text.len_lines() - 2) { - end = line_end_char_index(&text.slice(..), line_end + 1); + let start = text.line_to_char(start_line); + let mut end = text.line_to_char(end_line); + + if pos.from() == start && pos.to() == end { + end = text.line_to_char((end_line + 1).min(line_max)); } doc.set_selection(view.id, Selection::single(start, end)); -- cgit v1.2.3-70-g09d2