From a7c46206de4de6850fd126e4dd4e67c606d00b1c Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 5 Sep 2024 11:19:02 -0600 Subject: [PATCH] vim: Fix blackhole register (#17419) Closes: #17306 Release Notes: - vim: Fixed `"_` register writes overwriting `"` register. --- crates/vim/src/state.rs | 8 +++++--- crates/vim/src/test.rs | 12 +++++++++++- crates/vim/test_data/test_blackhole_register.json | 11 +++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 crates/vim/test_data/test_blackhole_register.json diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index 1255c783f4..1d642e990f 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -218,23 +218,25 @@ impl VimGlobals { let yanked = current.clone(); self.registers.insert('"', yanked); } else { - self.registers.insert('"', content.clone()); match lower { '_' | ':' | '.' | '%' | '#' | '=' | '/' => {} '+' => { + self.registers.insert('"', content.clone()); cx.write_to_clipboard(content.into()); } '*' => { + self.registers.insert('"', content.clone()); #[cfg(target_os = "linux")] cx.write_to_primary(content.into()); #[cfg(not(target_os = "linux"))] cx.write_to_clipboard(content.into()); } '"' => { - self.registers.insert('0', content.clone()); - self.registers.insert('"', content); + self.registers.insert('"', content.clone()); + self.registers.insert('0', content); } _ => { + self.registers.insert('"', content.clone()); self.registers.insert(lower, content); } } diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 2752b039de..9c61e9cd93 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -1424,7 +1424,17 @@ async fn test_record_replay_recursion(cx: &mut gpui::TestAppContext) { cx.simulate_shared_keystrokes(".").await; cx.simulate_shared_keystrokes(".").await; cx.simulate_shared_keystrokes(".").await; - cx.shared_state().await.assert_eq("ˇhello world"); // takes a _long_ time + cx.shared_state().await.assert_eq("ˇhello world"); +} + +#[gpui::test] +async fn test_blackhole_register(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + + cx.set_shared_state("ˇhello world").await; + cx.simulate_shared_keystrokes("d i w \" _ d a w").await; + cx.simulate_shared_keystrokes("p").await; + cx.shared_state().await.assert_eq("hellˇo"); } #[gpui::test] diff --git a/crates/vim/test_data/test_blackhole_register.json b/crates/vim/test_data/test_blackhole_register.json new file mode 100644 index 0000000000..e16bb3abe3 --- /dev/null +++ b/crates/vim/test_data/test_blackhole_register.json @@ -0,0 +1,11 @@ +{"Put":{"state":"ˇhello world"}} +{"Key":"d"} +{"Key":"i"} +{"Key":"w"} +{"Key":"\""} +{"Key":"_"} +{"Key":"d"} +{"Key":"a"} +{"Key":"w"} +{"Key":"p"} +{"Get":{"state":"hellˇo","mode":"Normal"}}