Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit select mode on replace commands #4554

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ fn replace(cx: &mut Context) {
});

apply_transaction(&transaction, doc, view);
exit_select_mode(cx);
}
})
}
Expand Down Expand Up @@ -3580,18 +3581,19 @@ fn replace_with_yanked(cx: &mut Context) {
});

apply_transaction(&transaction, doc, view);
exit_select_mode(cx);
}
}
}

fn replace_selections_with_clipboard_impl(
editor: &mut Editor,
cx: &mut Context,
clipboard_type: ClipboardType,
count: usize,
) -> anyhow::Result<()> {
let (view, doc) = current!(editor);
let count = cx.count();
let (view, doc) = current!(cx.editor);

match editor.clipboard_provider.get_contents(clipboard_type) {
match cx.editor.clipboard_provider.get_contents(clipboard_type) {
Ok(contents) => {
let selection = doc.selection(view.id);
let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
Expand All @@ -3604,18 +3606,20 @@ fn replace_selections_with_clipboard_impl(

apply_transaction(&transaction, doc, view);
doc.append_changes_to_history(view.id);
Ok(())
}
Err(e) => Err(e.context("Couldn't get system clipboard contents")),
Err(e) => return Err(e.context("Couldn't get system clipboard contents")),
}

exit_select_mode(cx);
Ok(())
}

fn replace_selections_with_clipboard(cx: &mut Context) {
let _ = replace_selections_with_clipboard_impl(cx.editor, ClipboardType::Clipboard, cx.count());
let _ = replace_selections_with_clipboard_impl(cx, ClipboardType::Clipboard);
}

fn replace_selections_with_primary_clipboard(cx: &mut Context) {
let _ = replace_selections_with_clipboard_impl(cx.editor, ClipboardType::Selection, cx.count());
let _ = replace_selections_with_clipboard_impl(cx, ClipboardType::Selection);
}

fn paste(cx: &mut Context, pos: Paste) {
Expand Down