From 82338e2c477a4e33e729632224f7238d521c0b37 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 5 Mar 2025 03:34:52 +0100 Subject: [PATCH] vim: Fix clear exchange not working (#25804) Fixes two issues with the Vim exchange implementation: 1. The clear exchange implementation **didn't** clear the exchange. This was due to us asking the editor to clear normal highlights instead of background highlights. 2. Calling clear exchange also wouldn't cause the operator to be cleared, so you would be left in operator = "cx". I've added tests for both of these cases. Partially closes #25750. It doesn't address the problem with dot repeat not working for my custom bindings, but I don't know what would cause that. I'd love to hear some thoughts on why that is. That might be a problem on my part or it might be something with the code. Input would be appreciated. Release Notes: - Fixed: Vim exchange's "clear exchange" function didn't clear the exchange and kept you in operator pending mode. --- crates/vim/src/replace.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/replace.rs b/crates/vim/src/replace.rs index 77f8af1f47598a84c98b6bc36b2eddaba4cd8382..ada0194f0e836fd891085a201b8aba1935c9a4f2 100644 --- a/crates/vim/src/replace.rs +++ b/crates/vim/src/replace.rs @@ -170,8 +170,9 @@ impl Vim { pub fn clear_exchange(&mut self, window: &mut Window, cx: &mut Context) { self.stop_recording(cx); self.update_editor(window, cx, |_, editor, _, cx| { - editor.clear_highlights::(cx); + editor.clear_background_highlights::(cx); }); + self.clear_operator(window, cx); } pub fn exchange_motion( @@ -483,4 +484,27 @@ mod test { cx.simulate_keystrokes("c x t r w c x i w"); cx.assert_state("hello ˇworld", Mode::Normal); } + + #[gpui::test] + async fn test_clear_exchange_clears_operator(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + + cx.set_state("ˇirrelevant", Mode::Normal); + cx.simulate_keystrokes("c x c"); + + assert_eq!(cx.active_operator(), None); + } + + #[gpui::test] + async fn test_clear_exchange(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + + cx.set_state("ˇhello world", Mode::Normal); + cx.simulate_keystrokes("c x i w c x c"); + + cx.update_editor(|editor, window, cx| { + let highlights = editor.all_text_background_highlights(window, cx); + assert_eq!(0, highlights.len()); + }); + } }