Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

vim: Fix editor paste not using clipboard in visual mode (#44347)

Mayank Verma7cbe25fda531
diff --git a/crates/vim/src/normal/paste.rs b/crates/vim/src/normal/paste.rs
index 978c882f059..82af828deb8 100644
--- a/crates/vim/src/normal/paste.rs
+++ b/crates/vim/src/normal/paste.rs
@@ -773,6 +773,52 @@ mod test {
"});
}
+ #[gpui::test]
+ async fn test_paste_system_clipboard_never(cx: &mut gpui::TestAppContext) {
+ let mut cx = VimTestContext::new(cx, true).await;
+
+ cx.update_global(|store: &mut SettingsStore, cx| {
+ store.update_user_settings(cx, |s| {
+ s.vim.get_or_insert_default().use_system_clipboard = Some(UseSystemClipboard::Never)
+ });
+ });
+
+ cx.set_state(
+ indoc! {"
+ ˇThe quick brown
+ fox jumps over
+ the lazy dog"},
+ Mode::Normal,
+ );
+
+ cx.write_to_clipboard(ClipboardItem::new_string("something else".to_string()));
+
+ cx.simulate_keystrokes("d d");
+ cx.assert_state(
+ indoc! {"
+ ˇfox jumps over
+ the lazy dog"},
+ Mode::Normal,
+ );
+
+ cx.simulate_keystrokes("shift-v p");
+ cx.assert_state(
+ indoc! {"
+ ˇThe quick brown
+ the lazy dog"},
+ Mode::Normal,
+ );
+
+ cx.simulate_keystrokes("shift-v");
+ cx.dispatch_action(editor::actions::Paste);
+ cx.assert_state(
+ indoc! {"
+ ˇsomething else
+ the lazy dog"},
+ Mode::Normal,
+ );
+ }
+
#[gpui::test]
async fn test_numbered_registers(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs
index 1ffcf7e2224..9a9a1a001c3 100644
--- a/crates/vim/src/vim.rs
+++ b/crates/vim/src/vim.rs
@@ -924,6 +924,7 @@ impl Vim {
|vim, _: &editor::actions::Paste, window, cx| match vim.mode {
Mode::Replace => vim.paste_replace(window, cx),
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
+ vim.selected_register.replace('+');
vim.paste(&VimPaste::default(), window, cx);
}
_ => {