Use an enum to represent yank decision during deletion of a selection (#10148)

pull/10159/head
Harishankar G 8 months ago committed by GitHub
parent 3e2b85c61b
commit 962c714185
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2617,14 +2617,19 @@ fn selection_is_linewise(selection: &Selection, text: &Rope) -> bool {
}) })
} }
fn delete_selection_impl(cx: &mut Context, op: Operation, yank: bool) { enum YankAction {
Yank,
NoYank,
}
fn delete_selection_impl(cx: &mut Context, op: Operation, yank: YankAction) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let selection = doc.selection(view.id); let selection = doc.selection(view.id);
let only_whole_lines = selection_is_linewise(selection, doc.text()); let only_whole_lines = selection_is_linewise(selection, doc.text());
if cx.register != Some('_') && yank { if cx.register != Some('_') && matches!(yank, YankAction::Yank) {
// first yank the selection // yank the selection
let text = doc.text().slice(..); let text = doc.text().slice(..);
let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect(); let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
let reg_name = cx.register.unwrap_or('"'); let reg_name = cx.register.unwrap_or('"');
@ -2632,9 +2637,9 @@ fn delete_selection_impl(cx: &mut Context, op: Operation, yank: bool) {
cx.editor.set_error(err.to_string()); cx.editor.set_error(err.to_string());
return; return;
} }
}; }
// then delete // delete the selection
let transaction = let transaction =
Transaction::delete_by_selection(doc.text(), selection, |range| (range.from(), range.to())); Transaction::delete_by_selection(doc.text(), selection, |range| (range.from(), range.to()));
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
@ -2700,19 +2705,19 @@ fn delete_by_selection_insert_mode(
} }
fn delete_selection(cx: &mut Context) { fn delete_selection(cx: &mut Context) {
delete_selection_impl(cx, Operation::Delete, true); delete_selection_impl(cx, Operation::Delete, YankAction::Yank);
} }
fn delete_selection_noyank(cx: &mut Context) { fn delete_selection_noyank(cx: &mut Context) {
delete_selection_impl(cx, Operation::Delete, false); delete_selection_impl(cx, Operation::Delete, YankAction::NoYank);
} }
fn change_selection(cx: &mut Context) { fn change_selection(cx: &mut Context) {
delete_selection_impl(cx, Operation::Change, true); delete_selection_impl(cx, Operation::Change, YankAction::Yank);
} }
fn change_selection_noyank(cx: &mut Context) { fn change_selection_noyank(cx: &mut Context) {
delete_selection_impl(cx, Operation::Change, false); delete_selection_impl(cx, Operation::Change, YankAction::NoYank);
} }
fn collapse_selection(cx: &mut Context) { fn collapse_selection(cx: &mut Context) {

Loading…
Cancel
Save