Skip to content

Commit

Permalink
vim: Support paste with count (#11621)
Browse files Browse the repository at this point in the history
Fixes: #10842



Release Notes:

- vim: Fix pasting with a count (#10842)
  • Loading branch information
ConradIrwin committed May 9, 2024
1 parent bca639b commit aa5113c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
40 changes: 39 additions & 1 deletion crates/vim/src/normal/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn system_clipboard_is_newer(vim: &Vim, cx: &mut AppContext) -> bool {
fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {
Vim::update(cx, |vim, cx| {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
vim.update_active_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(cx);
editor.transact(cx, |editor, cx| {
Expand Down Expand Up @@ -178,7 +179,7 @@ fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {
if *preserve {
new_selections.push((anchor, line_mode, is_multiline));
}
edits.push((point_range, to_insert));
edits.push((point_range, to_insert.repeat(count)));
original_indent_columns.extend(original_indent_column);
}

Expand Down Expand Up @@ -599,4 +600,41 @@ mod test {
Mode::Normal,
);
}

#[gpui::test]
async fn test_paste_count(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

cx.set_shared_state(indoc! {"
onˇe
two
three
"})
.await;
cx.simulate_shared_keystrokes(["y", "y", "3", "p"]).await;
cx.assert_shared_state(indoc! {"
one
ˇone
one
one
two
three
"})
.await;

cx.set_shared_state(indoc! {"
one
ˇtwo
three
"})
.await;
cx.simulate_shared_keystrokes(["y", "$", "$", "3", "p"])
.await;
cx.assert_shared_state(indoc! {"
one
twotwotwotwˇo
three
"})
.await;
}
}
13 changes: 13 additions & 0 deletions crates/vim/test_data/test_paste_count.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{"Put":{"state":"onˇe\ntwo\nthree\n"}}
{"Key":"y"}
{"Key":"y"}
{"Key":"3"}
{"Key":"p"}
{"Get":{"state":"one\nˇone\none\none\ntwo\nthree\n","mode":"Normal"}}
{"Put":{"state":"one\nˇtwo\nthree\n"}}
{"Key":"y"}
{"Key":"$"}
{"Key":"$"}
{"Key":"3"}
{"Key":"p"}
{"Get":{"state":"one\ntwotwotwotwˇo\nthree\n","mode":"Normal"}}

0 comments on commit aa5113c

Please sign in to comment.