aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 25f00f98..bf822944 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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;
}
@@ -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())),
@@ -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);
}
@@ -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(
@@ -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")),
@@ -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);
}
}