diff options
author | Ivan Tham | 2022-04-23 08:03:52 +0000 |
---|---|---|
committer | GitHub | 2022-04-23 08:03:52 +0000 |
commit | c1d3d49f3f47a991e38e21d96dee3f9081c9a663 (patch) | |
tree | ca0b0ab75c8c439d60f8d3ce218ec23287a24442 | |
parent | dd5a7c6191314b22347c323e8cda8aff225e21ba (diff) |
Fix ctrl-u on insert behavior (#1957)
* Fix ctrl-u on insert behavior
Now should follow vim behavior more
- no longer remove text on cursor
- no longer remove selected text while inserting
- first kill to start non-whitespace, start, previous new line
* Add comment for c-u parts
-rw-r--r-- | helix-term/src/commands.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4e13f74a..504de73f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -681,7 +681,24 @@ fn kill_to_line_start(cx: &mut Context) { let selection = doc.selection(view.id).clone().transform(|range| { let line = range.cursor_line(text); - range.put_cursor(text, text.line_to_char(line), true) + let first_char = text.line_to_char(line); + let anchor = range.cursor(text); + let head = if anchor == first_char && line != 0 { + // select until previous line + line_end_char_index(&text, line - 1) + } else if let Some(pos) = find_first_non_whitespace_char(text.line(line)) { + if first_char + pos < anchor { + // select until first non-blank in line if cursor is after it + first_char + pos + } else { + // select until start of line + first_char + } + } else { + // select until start of line + first_char + }; + Range::new(head, anchor) }); delete_selection_insert_mode(doc, view, &selection); } |