on master help sign in
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

commitc1d3d49f3f47a991e38e21d96dee3f9081c9a663 authorIvan Tham <pickfire@riseup.net> dateSat 23 Apr 2022, 16:03 (5 years ago) parentdd5a7c6
1 file changed+18−1
helix-term/src/commands.rs+18−1
helix-term/src/commands.rs+18−1
@@ -681,7 +681,24 @@ fn kill_to_line_start(cx: &mut Context) {
681681
682682 let selection = doc.selection(view.id).clone().transform(|range| {
683683 let line = range.cursor_line(text);
684− range.put_cursor(text, text.line_to_char(line), true)
684+ let first_char = text.line_to_char(line);
685+ let anchor = range.cursor(text);
686+ let head = if anchor == first_char && line != 0 {
687+ // select until previous line
688+ line_end_char_index(&text, line - 1)
689+ } else if let Some(pos) = find_first_non_whitespace_char(text.line(line)) {
690+ if first_char + pos < anchor {
691+ // select until first non-blank in line if cursor is after it
692+ first_char + pos
693+ } else {
694+ // select until start of line
695+ first_char
696+ }
697+ } else {
698+ // select until start of line
699+ first_char
700+ };
701+ Range::new(head, anchor)
685702 });
686703 delete_selection_insert_mode(doc, view, &selection);
687704}