From 25d4ebe30d7920bc087f004075048f62f53726af Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Mon, 20 Feb 2023 16:31:26 +0100 Subject: don't move cursor while forward deleting in append mode Currently, when forward deleting (`delete_char_forward` bound to `del`, `delete_word_forward`, `kill_to_line_end`) the cursor is moved to the left in append mode (or generally when the cursor is at the end of the selection). For example in a document `|abc|def` (|indicates selection) if enter append mode the cursor is moved to `c` and the selection becomes: `|abcd|ef`. When deleting forward (`del`) `d` is deleted. The expectation would be that the selection doesn't shrink so that `del` again deletes `e` and then `f`. This would look as follows: `|abcd|ef` `|abce|f` `|abcf|` `|abc |` This is inline with how other editors like kakoune work. However, helix currently moves the selection backwards leading to the following behavior: `|abcd|ef` `|abc|ef` `|ab|ef` `ef` This means that `delete_char_forward` essentially acts like `delete_char_backward` after deleting the first character in append mode. To fix the problem the cursor must be moved to the right while deleting forward (first fix in this commit). Furthermore, when the EOF char is reached a newline char must be inserted (just like when entering appendmode) to prevent the cursor from moving to the right --- helix-core/src/transaction.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'helix-core') diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 06efe259..f4f94b54 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -570,6 +570,11 @@ impl Transaction { Self::from(changeset) } + pub fn insert_at_eof(mut self, text: Tendril) -> Transaction { + self.changes.insert(text); + self + } + /// Generate a transaction with a change per selection range. pub fn change_by_selection(doc: &Rope, selection: &Selection, f: F) -> Self where -- cgit v1.2.3-70-g09d2