@@ -9,7 +9,6 @@ use helix_core::{
99 numbers::NumberIncrementor,
1010 object, pos_at_coords,
1111 regex::{self, Regex, RegexBuilder},
12− register::Register,
1312 search, selection, surround, textobject,
1413 unicode::width::UnicodeWidthChar,
1514 LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril,
@@ -232,7 +231,9 @@ impl Command {
232231 extend_line, "Select current line, if already selected, extend to next line",
233232 extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
234233 delete_selection, "Delete selection",
234+ delete_selection_noyank, "Delete selection, without yanking",
235235 change_selection, "Change selection (delete and enter insert mode)",
236+ change_selection_noyank, "Change selection (delete and enter insert mode, without yanking)",
236237 collapse_selection, "Collapse selection onto a single cursor",
237238 flip_selections, "Flip selection cursor and anchor",
238239 insert_mode, "Insert before selection",
@@ -1693,19 +1694,42 @@ fn extend_to_line_bounds(cx: &mut Context) {
16931694 );
16941695}
16951696
1696−fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId) {
1697+enum Operation {
1698+ Delete,
1699+ Change,
1700+}
1701+
1702+fn delete_selection_impl(cx: &mut Context, op: Operation) {
1703+ let (view, doc) = current!(cx.editor);
1704+
16971705 let text = doc.text().slice(..);
1698− let selection = doc.selection(view_id);
1706+ let selection = doc.selection(view.id);
16991707
1700− // first yank the selection
1701− let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
1702− reg.write(values);
1708+ if cx.register != Some('_') {
1709+ // first yank the selection
1710+ let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
1711+ let reg_name = cx.register.unwrap_or('"');
1712+ let registers = &mut cx.editor.registers;
1713+ let reg = registers.get_mut(reg_name);
1714+ reg.write(values);
1715+ };
17031716
17041717 // then delete
17051718 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
17061719 (range.from(), range.to(), None)
17071720 });
1708− doc.apply(&transaction, view_id);
1721+ doc.apply(&transaction, view.id);
1722+
1723+ match op {
1724+ Operation::Delete => {
1725+ doc.append_changes_to_history(view.id);
1726+ // exit select mode, if currently in select mode
1727+ exit_select_mode(cx);
1728+ }
1729+ Operation::Change => {
1730+ enter_insert_mode(doc);
1731+ }
1732+ }
17091733}
17101734
17111735#[inline]
@@ -1720,25 +1744,21 @@ fn delete_selection_insert_mode(doc: &mut Document, view: &View, selection: &Sel
17201744}
17211745
17221746fn delete_selection(cx: &mut Context) {
1723− let reg_name = cx.register.unwrap_or('"');
1724− let (view, doc) = current!(cx.editor);
1725− let registers = &mut cx.editor.registers;
1726− let reg = registers.get_mut(reg_name);
1727− delete_selection_impl(reg, doc, view.id);
1728−
1729− doc.append_changes_to_history(view.id);
1747+ delete_selection_impl(cx, Operation::Delete);
1748+}
17301749
1731− // exit select mode, if currently in select mode
1732− exit_select_mode(cx);
1750+fn delete_selection_noyank(cx: &mut Context) {
1751+ cx.register = Some('_');
1752+ delete_selection_impl(cx, Operation::Delete);
17331753}
17341754
17351755fn change_selection(cx: &mut Context) {
1736− let reg_name = cx.register.unwrap_or('"');
1737− let (view, doc) = current!(cx.editor);
1738− let registers = &mut cx.editor.registers;
1739− let reg = registers.get_mut(reg_name);
1740− delete_selection_impl(reg, doc, view.id);
1741− enter_insert_mode(doc);
1756+ delete_selection_impl(cx, Operation::Change);
1757+}
1758+
1759+fn change_selection_noyank(cx: &mut Context) {
1760+ cx.register = Some('_');
1761+ delete_selection_impl(cx, Operation::Change);
17421762}
17431763
17441764fn collapse_selection(cx: &mut Context) {