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

Select new pasted text in normal mode only #4824

Merged
merged 1 commit into from
Nov 21, 2022
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
21 changes: 15 additions & 6 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3467,7 +3467,14 @@ enum Paste {
Cursor,
}

fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Paste, count: usize) {
fn paste_impl(
values: &[String],
doc: &mut Document,
view: &mut View,
action: Paste,
count: usize,
mode: Mode,
) {
if values.is_empty() {
return;
}
Expand Down Expand Up @@ -3499,7 +3506,7 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Pa
let mut offset = 0;
let mut ranges = SmallVec::with_capacity(selection.len());

let transaction = Transaction::change_by_selection(text, selection, |range| {
let mut transaction = Transaction::change_by_selection(text, selection, |range| {
let pos = match (action, linewise) {
// paste linewise before
(Paste::Before, true) => text.line_to_char(text.char_to_line(range.from())),
Expand Down Expand Up @@ -3531,7 +3538,9 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Pa
(pos, pos, value)
});

let transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
if mode == Mode::Normal {
transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
}

apply_transaction(&transaction, doc, view);
}
Expand All @@ -3543,7 +3552,7 @@ pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
Mode::Normal => Paste::Before,
};
let (view, doc) = current!(cx.editor);
paste_impl(&[contents], doc, view, paste, count);
paste_impl(&[contents], doc, view, paste, count, cx.editor.mode);
}

fn paste_clipboard_impl(
Expand All @@ -3555,7 +3564,7 @@ fn paste_clipboard_impl(
let (view, doc) = current!(editor);
match editor.clipboard_provider.get_contents(clipboard_type) {
Ok(contents) => {
paste_impl(&[contents], doc, view, action, count);
paste_impl(&[contents], doc, view, action, count, editor.mode);
Ok(())
}
Err(e) => Err(e.context("Couldn't get system clipboard contents")),
Expand Down Expand Up @@ -3674,7 +3683,7 @@ fn paste(cx: &mut Context, pos: Paste) {
let registers = &mut cx.editor.registers;

if let Some(values) = registers.read(reg_name) {
paste_impl(values, doc, view, pos, count);
paste_impl(values, doc, view, pos, count, cx.editor.mode);
}
}

Expand Down