From a59da3634bb3b84eb4a1d5a9ebeb1afe0f0a89ae Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 20 Sep 2023 16:41:40 -0600 Subject: [PATCH] Fix backward search from command --- crates/vim/src/command.rs | 27 ++++++++++++++++++- crates/vim/src/normal/search.rs | 7 ++++- crates/vim/test_data/test_command_search.json | 11 ++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 crates/vim/test_data/test_command_search.json diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index 7aaf3d8024..2ad8f0522e 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -355,8 +355,33 @@ mod test { dd ˇcc"}) .await; + } - cx.simulate_shared_keystrokes([":", "%", "s", "/", "/", "/", "enter"]) + #[gpui::test] + async fn test_command_search(cx: &mut TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + + cx.set_shared_state(indoc! {" + ˇa + b + a + c"}) + .await; + cx.simulate_shared_keystrokes([":", "/", "b", "enter"]) + .await; + cx.assert_shared_state(indoc! {" + a + ˇb + a + c"}) + .await; + cx.simulate_shared_keystrokes([":", "?", "a", "enter"]) + .await; + cx.assert_shared_state(indoc! {" + ˇa + b + a + c"}) .await; } diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 8ef0718c32..e76da1dfc5 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -195,10 +195,15 @@ fn find_command(workspace: &mut Workspace, action: &FindCommand, cx: &mut ViewCo }); let Some(search) = search else { return }; let search_bar = search_bar.downgrade(); + let direction = if action.backwards { + Direction::Prev + } else { + Direction::Next + }; cx.spawn(|_, mut cx| async move { search.await?; search_bar.update(&mut cx, |search_bar, cx| { - search_bar.select_match(Direction::Next, 1, cx) + search_bar.select_match(direction, 1, cx) })?; anyhow::Ok(()) }) diff --git a/crates/vim/test_data/test_command_search.json b/crates/vim/test_data/test_command_search.json new file mode 100644 index 0000000000..705ce51fb7 --- /dev/null +++ b/crates/vim/test_data/test_command_search.json @@ -0,0 +1,11 @@ +{"Put":{"state":"ˇa\nb\na\nc"}} +{"Key":":"} +{"Key":"/"} +{"Key":"b"} +{"Key":"enter"} +{"Get":{"state":"a\nˇb\na\nc","mode":"Normal"}} +{"Key":":"} +{"Key":"?"} +{"Key":"a"} +{"Key":"enter"} +{"Get":{"state":"ˇa\nb\na\nc","mode":"Normal"}}