@@ -27,8 +27,8 @@ use helix_core::{
27 textobject,
27 textobject,
28 tree_sitter::Node,
28 tree_sitter::Node,
29 unicode::width::UnicodeWidthChar,
29 unicode::width::UnicodeWidthChar,
30− visual_offset_from_block, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice,
30+ visual_offset_from_block, Deletion, LineEnding, Position, Range, Rope, RopeGraphemes,
31− Selection, SmallVec, Tendril, Transaction,
31+ RopeSlice, Selection, SmallVec, Tendril, Transaction,
33use helix_view::{
33use helix_view::{
34 clipboard::ClipboardType,
34 clipboard::ClipboardType,
@@ -795,10 +795,7 @@ fn extend_to_line_start(cx: &mut Context) {
797fn kill_to_line_start(cx: &mut Context) {
797fn kill_to_line_start(cx: &mut Context) {
798− let (view, doc) = current!(cx.editor);
798+ delete_by_selection_insert_mode(cx, move |text, range| {
799− let text = doc.text().slice(..);
801− let selection = doc.selection(view.id).clone().transform(|range| {
802 let line = range.cursor_line(text);
799 let line = range.cursor_line(text);
803 let first_char = text.line_to_char(line);
800 let first_char = text.line_to_char(line);
804 let anchor = range.cursor(text);
801 let anchor = range.cursor(text);
@@ -817,32 +814,23 @@ fn kill_to_line_start(cx: &mut Context) {
817 // select until start of line
814 // select until start of line
818 first_char
815 first_char
820− Range::new(head, anchor)
817+ (head, anchor)
822− delete_selection_insert_mode(doc, view, &selection);
824− lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
827fn kill_to_line_end(cx: &mut Context) {
821fn kill_to_line_end(cx: &mut Context) {
828− let (view, doc) = current!(cx.editor);
822+ delete_by_selection_insert_mode(cx, |text, range| {
829− let text = doc.text().slice(..);
831− let selection = doc.selection(view.id).clone().transform(|range| {
832 let line = range.cursor_line(text);
823 let line = range.cursor_line(text);
833 let line_end_pos = line_end_char_index(&text, line);
824 let line_end_pos = line_end_char_index(&text, line);
834 let pos = range.cursor(text);
825 let pos = range.cursor(text);
836− let mut new_range = range.put_cursor(text, line_end_pos, true);
827+ // if the cursor is on the newline char delete that
837− // don't want to remove the line separator itself if the cursor doesn't reach the end of line.
838− if pos != line_end_pos {
828+ if pos == line_end_pos {
829+ (pos, text.line_to_char(line + 1))
839− new_range.head = line_end_pos;
831+ (pos, line_end_pos)
843− delete_selection_insert_mode(doc, view, &selection);
845− lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
848fn goto_first_nonwhitespace(cx: &mut Context) {
836fn goto_first_nonwhitespace(cx: &mut Context) {
@@ -2331,10 +2319,18 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2333#[inline]
2321#[inline]
2334−fn delete_selection_insert_mode(doc: &mut Document, view: &mut View, selection: &Selection) {
2322+fn delete_by_selection_insert_mode(
2324+ mut f: impl FnMut(RopeSlice, &Range) -> Deletion,
2326+ let (view, doc) = current!(cx.editor);
2327+ let text = doc.text().slice(..);
2335 let transaction =
2328 let transaction =
2336− Transaction::delete_by_selection(doc.text(), selection, |range| (range.from(), range.to()));
2329+ Transaction::delete_by_selection(doc.text(), doc.selection(view.id), |range| {
2337 doc.apply(&transaction, view.id);
2332 doc.apply(&transaction, view.id);
2333+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
2340fn delete_selection(cx: &mut Context) {
2336fn delete_selection(cx: &mut Context) {
@@ -3494,46 +3490,28 @@ pub mod insert {
3495 pub fn delete_char_forward(cx: &mut Context) {
3491 pub fn delete_char_forward(cx: &mut Context) {
3496 let count = cx.count();
3492 let count = cx.count();
3497− let (view, doc) = current!(cx.editor);
3493+ delete_by_selection_insert_mode(cx, |text, range| {
3498− let text = doc.text().slice(..);
3500− Transaction::delete_by_selection(doc.text(), doc.selection(view.id), |range| {
3501− let pos = range.cursor(text);
3494+ let pos = range.cursor(text);
3502− (pos, graphemes::nth_next_grapheme_boundary(text, pos, count))
3495+ (pos, graphemes::nth_next_grapheme_boundary(text, pos, count))
3504− doc.apply(&transaction, view.id);
3506− lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3509 pub fn delete_word_backward(cx: &mut Context) {
3499 pub fn delete_word_backward(cx: &mut Context) {
3510 let count = cx.count();
3500 let count = cx.count();
3511− let (view, doc) = current!(cx.editor);
3501+ delete_by_selection_insert_mode(cx, |text, range| {
3512− let text = doc.text().slice(..);
3514− let selection = doc.selection(view.id).clone().transform(|range| {
3515− let anchor = movement::move_prev_word_start(text, range, count).from();
3502+ let anchor = movement::move_prev_word_start(text, *range, count).from();
3516 let next = Range::new(anchor, range.cursor(text));
3503 let next = Range::new(anchor, range.cursor(text));
3517− exclude_cursor(text, next, range)
3504+ let range = exclude_cursor(text, next, *range);
3505+ (range.from(), range.to())
3519− delete_selection_insert_mode(doc, view, &selection);
3521− lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3524 pub fn delete_word_forward(cx: &mut Context) {
3509 pub fn delete_word_forward(cx: &mut Context) {
3525 let count = cx.count();
3510 let count = cx.count();
3526− let (view, doc) = current!(cx.editor);
3511+ delete_by_selection_insert_mode(cx, |text, range| {
3527− let text = doc.text().slice(..);
3529− let selection = doc.selection(view.id).clone().transform(|range| {
3530− let head = movement::move_next_word_end(text, range, count).to();
3512+ let head = movement::move_next_word_end(text, *range, count).to();
3531− Range::new(range.cursor(text), head)
3513+ (range.cursor(text), head)
3534− delete_selection_insert_mode(doc, view, &selection);
3536− lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);