From e166da2ab051279f3086e0942f6b7adb1a641a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 30 Mar 2021 18:27:45 +0900 Subject: [PATCH] fix: A (append to line) was inserting before last char. --- helix-term/src/commands.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8dc69544..7233f1da 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -922,18 +922,25 @@ fn selection_lines(doc: &Rope, selection: &Selection) -> Vec { // I inserts at the start of each line with a selection pub fn prepend_to_line(cx: &mut Context) { + move_line_start(cx); let doc = cx.doc(); enter_insert_mode(doc); - - move_line_start(cx); } // A inserts at the end of each line with a selection pub fn append_to_line(cx: &mut Context) { + move_line_end(cx); + let doc = cx.doc(); enter_insert_mode(doc); - move_line_end(cx); + // offset by another 1 char since move_line_end will position on the last char, we want to + // append past that + let selection = doc.selection().transform(|range| { + let pos = range.head + 1; + Range::new(pos, pos) + }); + doc.set_selection(selection); } // o inserts a new line after each line with a selection