From c43969eaeda8bb8455227c6e04dbdb391ec5e7d9 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 11 Dec 2023 16:53:43 -0700 Subject: [PATCH 1/5] Uncomment editor event tests --- crates/vim2/src/editor_events.rs | 61 +++++++++++++++++--------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/crates/vim2/src/editor_events.rs b/crates/vim2/src/editor_events.rs index b915bd779e..0e2a1451fe 100644 --- a/crates/vim2/src/editor_events.rs +++ b/crates/vim2/src/editor_events.rs @@ -65,35 +65,40 @@ fn released(entity_id: EntityId, cx: &mut WindowContext) { }); } -// #[cfg(test)] -// mod test { -// use crate::{test::VimTestContext, Vim}; -// use editor::Editor; -// use gpui::{Context, Entity}; -// use language::Buffer; +#[cfg(test)] +mod test { + use crate::{test::VimTestContext, Vim}; + use editor::Editor; + use gpui::{Context, Entity}; + use language::Buffer; -// // regression test for blur called with a different active editor -// #[gpui::test] -// async fn test_blur_focus(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, true).await; + // regression test for blur called with a different active editor + #[gpui::test] + async fn test_blur_focus(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; -// let buffer = cx.build_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); -// let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx)); -// let editor2 = cx -// .update(|cx| window2.update(cx, |editor, cx| cx.view())) -// .unwrap(); + let buffer = cx.build_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); + let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx)); + let editor2 = cx + .update(|cx| { + window2.update(cx, |_, cx| { + cx.focus_self(); + cx.view().clone() + }) + }) + .unwrap(); -// cx.update(|cx| { -// let vim = Vim::read(cx); -// assert_eq!( -// vim.active_editor.unwrap().entity_id().unwrap(), -// editor2.entity_id() -// ) -// }); + cx.update(|cx| { + let vim = Vim::read(cx); + assert_eq!( + vim.active_editor.as_ref().unwrap().entity_id(), + editor2.entity_id(), + ) + }); -// // no panic when blurring an editor in a different window. -// cx.update_editor(|editor1, cx| { -// editor1.focus_out(cx.handle().into_any(), cx); -// }); -// } -// } + // no panic when blurring an editor in a different window. + cx.update_editor(|editor1, cx| { + editor1.handle_blur(cx); + }); + } +} From 3088cbea6895dede6611d6e2fe27b45421e173fa Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 12 Dec 2023 15:29:17 -0700 Subject: [PATCH 2/5] Uncomment vim search tests --- crates/vim2/src/normal/search.rs | 210 +++++++++++++++---------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/crates/vim2/src/normal/search.rs b/crates/vim2/src/normal/search.rs index 3873c5b78b..7b5f4d3e59 100644 --- a/crates/vim2/src/normal/search.rs +++ b/crates/vim2/src/normal/search.rs @@ -345,133 +345,133 @@ fn parse_replace_all(query: &str) -> Replacement { replacement } -// #[cfg(test)] -// mod test { -// use editor::DisplayPoint; -// use search::BufferSearchBar; +#[cfg(test)] +mod test { + use editor::DisplayPoint; + use search::BufferSearchBar; -// use crate::{state::Mode, test::VimTestContext}; + use crate::{state::Mode, test::VimTestContext}; -// #[gpui::test] -// async fn test_move_to_next(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, true).await; -// cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal); + #[gpui::test] + async fn test_move_to_next(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal); -// cx.simulate_keystrokes(["*"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); + cx.simulate_keystrokes(["*"]); + cx.run_until_parked(); + cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); -// cx.simulate_keystrokes(["*"]); -// cx.run_until_parked(); -// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); + cx.simulate_keystrokes(["*"]); + cx.run_until_parked(); + cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); -// cx.simulate_keystrokes(["#"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); + cx.simulate_keystrokes(["#"]); + cx.run_until_parked(); + cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); -// cx.simulate_keystrokes(["#"]); -// cx.run_until_parked(); -// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); + cx.simulate_keystrokes(["#"]); + cx.run_until_parked(); + cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); -// cx.simulate_keystrokes(["2", "*"]); -// cx.run_until_parked(); -// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); + cx.simulate_keystrokes(["2", "*"]); + cx.run_until_parked(); + cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); -// cx.simulate_keystrokes(["g", "*"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); + cx.simulate_keystrokes(["g", "*"]); + cx.run_until_parked(); + cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); -// cx.simulate_keystrokes(["n"]); -// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); + cx.simulate_keystrokes(["n"]); + cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); -// cx.simulate_keystrokes(["g", "#"]); -// cx.run_until_parked(); -// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); -// } + cx.simulate_keystrokes(["g", "#"]); + cx.run_until_parked(); + cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); + } -// #[gpui::test] -// async fn test_search(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, true).await; + #[gpui::test] + async fn test_search(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; -// cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); -// cx.simulate_keystrokes(["/", "c", "c"]); + cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); + cx.simulate_keystrokes(["/", "c", "c"]); -// let search_bar = cx.workspace(|workspace, cx| { -// workspace -// .active_pane() -// .read(cx) -// .toolbar() -// .read(cx) -// .item_of_type::() -// .expect("Buffer search bar should be deployed") -// }); + let search_bar = cx.workspace(|workspace, cx| { + workspace + .active_pane() + .read(cx) + .toolbar() + .read(cx) + .item_of_type::() + .expect("Buffer search bar should be deployed") + }); -// cx.update_view(search_bar, |bar, cx| { -// assert_eq!(bar.query(cx), "cc"); -// }); + cx.update_view(search_bar, |bar, cx| { + assert_eq!(bar.query(cx), "cc"); + }); -// cx.run_until_parked(); + cx.run_until_parked(); -// cx.update_editor(|editor, cx| { -// let highlights = editor.all_text_background_highlights(cx); -// assert_eq!(3, highlights.len()); -// assert_eq!( -// DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2), -// highlights[0].0 -// ) -// }); + cx.update_editor(|editor, cx| { + let highlights = editor.all_text_background_highlights(cx); + assert_eq!(3, highlights.len()); + assert_eq!( + DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2), + highlights[0].0 + ) + }); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); -// // n to go to next/N to go to previous -// cx.simulate_keystrokes(["n"]); -// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); -// cx.simulate_keystrokes(["shift-n"]); -// cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); + // n to go to next/N to go to previous + cx.simulate_keystrokes(["n"]); + cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); + cx.simulate_keystrokes(["shift-n"]); + cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); -// // ? to go to previous -// cx.simulate_keystrokes(["?", "enter"]); -// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); -// cx.simulate_keystrokes(["?", "enter"]); -// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); + // ? to go to previous + cx.simulate_keystrokes(["?", "enter"]); + cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); + cx.simulate_keystrokes(["?", "enter"]); + cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); -// // / to go to next -// cx.simulate_keystrokes(["/", "enter"]); -// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); + // / to go to next + cx.simulate_keystrokes(["/", "enter"]); + cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); -// // ?{search} to search backwards -// cx.simulate_keystrokes(["?", "b", "enter"]); -// cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); + // ?{search} to search backwards + cx.simulate_keystrokes(["?", "b", "enter"]); + cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); -// // works with counts -// cx.simulate_keystrokes(["4", "/", "c"]); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal); + // works with counts + cx.simulate_keystrokes(["4", "/", "c"]); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal); -// // check that searching resumes from cursor, not previous match -// cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); -// cx.simulate_keystrokes(["/", "d"]); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nbb\nˇdd\ncc\nbb\n", Mode::Normal); -// cx.update_editor(|editor, cx| editor.move_to_beginning(&Default::default(), cx)); -// cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); -// cx.simulate_keystrokes(["/", "b"]); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal); -// } + // check that searching resumes from cursor, not previous match + cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); + cx.simulate_keystrokes(["/", "d"]); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nbb\nˇdd\ncc\nbb\n", Mode::Normal); + cx.update_editor(|editor, cx| editor.move_to_beginning(&Default::default(), cx)); + cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); + cx.simulate_keystrokes(["/", "b"]); + cx.simulate_keystrokes(["enter"]); + cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal); + } -// #[gpui::test] -// async fn test_non_vim_search(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, false).await; -// cx.set_state("ˇone one one one", Mode::Normal); -// cx.simulate_keystrokes(["cmd-f"]); -// cx.run_until_parked(); + #[gpui::test] + async fn test_non_vim_search(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, false).await; + cx.set_state("ˇone one one one", Mode::Normal); + cx.simulate_keystrokes(["cmd-f"]); + cx.run_until_parked(); -// cx.assert_editor_state("«oneˇ» one one one"); -// cx.simulate_keystrokes(["enter"]); -// cx.assert_editor_state("one «oneˇ» one one"); -// cx.simulate_keystrokes(["shift-enter"]); -// cx.assert_editor_state("«oneˇ» one one one"); -// } -// } + cx.assert_editor_state("«oneˇ» one one one"); + cx.simulate_keystrokes(["enter"]); + cx.assert_editor_state("one «oneˇ» one one"); + cx.simulate_keystrokes(["shift-enter"]); + cx.assert_editor_state("«oneˇ» one one one"); + } +} From a656d11fed2d1aab6072c30dedca1129b2bd24d7 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 12 Dec 2023 18:39:42 -0700 Subject: [PATCH 3/5] Fix vim2 search tests --- crates/editor2/src/editor.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index b2040aff5b..76085aeca8 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -2171,7 +2171,6 @@ impl Editor { self.blink_manager.update(cx, BlinkManager::pause_blinking); cx.emit(EditorEvent::SelectionsChanged { local }); - cx.emit(SearchEvent::MatchesInvalidated); if self.selections.disjoint_anchors().len() == 1 { cx.emit(SearchEvent::ActiveMatchChanged) From a9349267ec522a314f2e140300fa8dbe8f88b646 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 12 Dec 2023 18:51:22 -0700 Subject: [PATCH 4/5] hah, oops --- crates/vim/src/editor_events.rs | 47 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/crates/vim/src/editor_events.rs b/crates/vim/src/editor_events.rs index 5464952b56..a6e0c4b801 100644 --- a/crates/vim/src/editor_events.rs +++ b/crates/vim/src/editor_events.rs @@ -63,31 +63,30 @@ fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) { }); } -// #[cfg(test)] -// mod test { -// use crate::{test::VimTestContext, Vim}; -// use editor::Editor; -// use gpui::View; -// use language::Buffer; +#[cfg(test)] +mod test { + use crate::{test::VimTestContext, Vim}; + use editor::Editor; + use gpui::View; + use language::Buffer; -// // regression test for blur called with a different active editor -// #[gpui::test] -// async fn test_blur_focus(cx: &mut gpui::TestAppContext) { -// let mut cx = VimTestContext::new(cx, true).await; + // regression test for blur called with a different active editor + #[gpui::test] + async fn test_blur_focus(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; -// let buffer = cx.add_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); -// let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx)); -// let editor2 = cx.read(|cx| window2.root(cx)).unwrap(); + let buffer = cx.add_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); + let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx)); + let editor2 = cx.read(|cx| window2.root(cx)).unwrap(); -// cx.update(|cx| { -// let vim = Vim::read(cx); -// assert_eq!(vim.active_editor.unwrap().id(), editor2.id()) -// }); + cx.update(|cx| { + let vim = Vim::read(cx); + assert_eq!(vim.active_editor.unwrap().id(), editor2.id()) + }); -// // no panic when blurring an editor in a different window. -// cx.update_editor(|editor1, cx| { -// todo!() -// // editor1.focus_out(cx.handle().into_any(), cx); -// }); -// } -// } + // no panic when blurring an editor in a different window. + cx.update_editor(|editor1, cx| { + editor1.focus_out(cx.handle().into_any(), cx); + }); + } +} From 1a86e4ff962a2831c883e9fa83edb8f12b774a20 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 12 Dec 2023 19:03:54 -0700 Subject: [PATCH 5/5] Fix vim toggle on welcome --- Cargo.lock | 1 + crates/welcome2/Cargo.toml | 2 +- crates/welcome2/src/welcome.rs | 26 ++++++++++++-------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86ae29e16b..8457edcd3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11423,6 +11423,7 @@ dependencies = [ "theme_selector2", "ui2", "util", + "vim2", "workspace2", ] diff --git a/crates/welcome2/Cargo.toml b/crates/welcome2/Cargo.toml index ce2e102ca0..e45af11e02 100644 --- a/crates/welcome2/Cargo.toml +++ b/crates/welcome2/Cargo.toml @@ -26,7 +26,7 @@ theme_selector = { package = "theme_selector2", path = "../theme_selector2" } util = { path = "../util" } picker = { package = "picker2", path = "../picker2" } workspace = { package = "workspace2", path = "../workspace2" } -# vim = { package = "vim2", path = "../vim2" } +vim = { package = "vim2", path = "../vim2" } anyhow.workspace = true log.workspace = true diff --git a/crates/welcome2/src/welcome.rs b/crates/welcome2/src/welcome.rs index 429f292edc..c553a04fc7 100644 --- a/crates/welcome2/src/welcome.rs +++ b/crates/welcome2/src/welcome.rs @@ -11,6 +11,7 @@ use gpui::{ use settings::{Settings, SettingsStore}; use std::sync::Arc; use ui::{prelude::*, Checkbox}; +use vim::VimModeSetting; use workspace::{ dock::DockPosition, item::{Item, ItemEvent}, @@ -128,29 +129,26 @@ impl Render for WelcomePage { .border_color(cx.theme().colors().border) .rounded_md() .child( - // todo!("vim setting") h_stack() .gap_2() .child( Checkbox::new( "enable-vim", - if false - /* VimSettings::get_global(cx).enabled */ - { + if VimModeSetting::get_global(cx).0 { ui::Selection::Selected } else { ui::Selection::Unselected }, - ), - // .on_click(cx.listener( - // move |this, selection, cx| { - // this.update_settings::( - // selection, - // cx, - // |settings, value| settings.enabled = value, - // ); - // }, - // )), + ) + .on_click(cx.listener( + move |this, selection, cx| { + this.update_settings::( + selection, + cx, + |setting, value| *setting = Some(value), + ); + }, + )), ) .child(Label::new("Enable vim mode")), )