- Uncomment editor event tests
- Uncomment vim search tests

Just command left

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2023-12-12 19:19:08 -07:00 committed by GitHub
commit b65129437f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 175 additions and 173 deletions

1
Cargo.lock generated
View file

@ -11423,6 +11423,7 @@ dependencies = [
"theme_selector2", "theme_selector2",
"ui2", "ui2",
"util", "util",
"vim2",
"workspace2", "workspace2",
] ]

View file

@ -2171,7 +2171,6 @@ impl Editor {
self.blink_manager.update(cx, BlinkManager::pause_blinking); self.blink_manager.update(cx, BlinkManager::pause_blinking);
cx.emit(EditorEvent::SelectionsChanged { local }); cx.emit(EditorEvent::SelectionsChanged { local });
cx.emit(SearchEvent::MatchesInvalidated);
if self.selections.disjoint_anchors().len() == 1 { if self.selections.disjoint_anchors().len() == 1 {
cx.emit(SearchEvent::ActiveMatchChanged) cx.emit(SearchEvent::ActiveMatchChanged)

View file

@ -63,31 +63,30 @@ fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
}); });
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::{test::VimTestContext, Vim}; use crate::{test::VimTestContext, Vim};
// use editor::Editor; use editor::Editor;
// use gpui::View; use gpui::View;
// use language::Buffer; use language::Buffer;
// // regression test for blur called with a different active editor // regression test for blur called with a different active editor
// #[gpui::test] #[gpui::test]
// async fn test_blur_focus(cx: &mut gpui::TestAppContext) { async fn test_blur_focus(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// let buffer = cx.add_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); 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 window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx));
// let editor2 = cx.read(|cx| window2.root(cx)).unwrap(); let editor2 = cx.read(|cx| window2.root(cx)).unwrap();
// cx.update(|cx| { cx.update(|cx| {
// let vim = Vim::read(cx); let vim = Vim::read(cx);
// assert_eq!(vim.active_editor.unwrap().id(), editor2.id()) assert_eq!(vim.active_editor.unwrap().id(), editor2.id())
// }); });
// // no panic when blurring an editor in a different window. // no panic when blurring an editor in a different window.
// cx.update_editor(|editor1, cx| { cx.update_editor(|editor1, cx| {
// todo!() editor1.focus_out(cx.handle().into_any(), cx);
// // editor1.focus_out(cx.handle().into_any(), cx); });
// }); }
// } }
// }

View file

@ -65,35 +65,40 @@ fn released(entity_id: EntityId, cx: &mut WindowContext) {
}); });
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use crate::{test::VimTestContext, Vim}; use crate::{test::VimTestContext, Vim};
// use editor::Editor; use editor::Editor;
// use gpui::{Context, Entity}; use gpui::{Context, Entity};
// use language::Buffer; use language::Buffer;
// // regression test for blur called with a different active editor // regression test for blur called with a different active editor
// #[gpui::test] #[gpui::test]
// async fn test_blur_focus(cx: &mut gpui::TestAppContext) { async fn test_blur_focus(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// let buffer = cx.build_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n")); 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 window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx));
// let editor2 = cx let editor2 = cx
// .update(|cx| window2.update(cx, |editor, cx| cx.view())) .update(|cx| {
// .unwrap(); window2.update(cx, |_, cx| {
cx.focus_self();
cx.view().clone()
})
})
.unwrap();
// cx.update(|cx| { cx.update(|cx| {
// let vim = Vim::read(cx); let vim = Vim::read(cx);
// assert_eq!( assert_eq!(
// vim.active_editor.unwrap().entity_id().unwrap(), vim.active_editor.as_ref().unwrap().entity_id(),
// editor2.entity_id() editor2.entity_id(),
// ) )
// }); });
// // no panic when blurring an editor in a different window. // no panic when blurring an editor in a different window.
// cx.update_editor(|editor1, cx| { cx.update_editor(|editor1, cx| {
// editor1.focus_out(cx.handle().into_any(), cx); editor1.handle_blur(cx);
// }); });
// } }
// } }

View file

@ -345,133 +345,133 @@ fn parse_replace_all(query: &str) -> Replacement {
replacement replacement
} }
// #[cfg(test)] #[cfg(test)]
// mod test { mod test {
// use editor::DisplayPoint; use editor::DisplayPoint;
// use search::BufferSearchBar; use search::BufferSearchBar;
// use crate::{state::Mode, test::VimTestContext}; use crate::{state::Mode, test::VimTestContext};
// #[gpui::test] #[gpui::test]
// async fn test_move_to_next(cx: &mut gpui::TestAppContext) { async fn test_move_to_next(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal); cx.set_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["*"]); cx.simulate_keystrokes(["*"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal);
// cx.simulate_keystrokes(["*"]); cx.simulate_keystrokes(["*"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["#"]); cx.simulate_keystrokes(["#"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal);
// cx.simulate_keystrokes(["#"]); cx.simulate_keystrokes(["#"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["2", "*"]); cx.simulate_keystrokes(["2", "*"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal); cx.assert_state("ˇhi\nhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["g", "*"]); cx.simulate_keystrokes(["g", "*"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal);
// cx.simulate_keystrokes(["n"]); cx.simulate_keystrokes(["n"]);
// cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal); cx.assert_state("hi\nhigh\nˇhi\n", Mode::Normal);
// cx.simulate_keystrokes(["g", "#"]); cx.simulate_keystrokes(["g", "#"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal); cx.assert_state("hi\nˇhigh\nhi\n", Mode::Normal);
// } }
// #[gpui::test] #[gpui::test]
// async fn test_search(cx: &mut gpui::TestAppContext) { async fn test_search(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await; let mut cx = VimTestContext::new(cx, true).await;
// cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); cx.set_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal);
// cx.simulate_keystrokes(["/", "c", "c"]); cx.simulate_keystrokes(["/", "c", "c"]);
// let search_bar = cx.workspace(|workspace, cx| { let search_bar = cx.workspace(|workspace, cx| {
// workspace workspace
// .active_pane() .active_pane()
// .read(cx) .read(cx)
// .toolbar() .toolbar()
// .read(cx) .read(cx)
// .item_of_type::<BufferSearchBar>() .item_of_type::<BufferSearchBar>()
// .expect("Buffer search bar should be deployed") .expect("Buffer search bar should be deployed")
// }); });
// cx.update_view(search_bar, |bar, cx| { cx.update_view(search_bar, |bar, cx| {
// assert_eq!(bar.query(cx), "cc"); assert_eq!(bar.query(cx), "cc");
// }); });
// cx.run_until_parked(); cx.run_until_parked();
// cx.update_editor(|editor, cx| { cx.update_editor(|editor, cx| {
// let highlights = editor.all_text_background_highlights(cx); let highlights = editor.all_text_background_highlights(cx);
// assert_eq!(3, highlights.len()); assert_eq!(3, highlights.len());
// assert_eq!( assert_eq!(
// DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2), DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2),
// highlights[0].0 highlights[0].0
// ) )
// }); });
// cx.simulate_keystrokes(["enter"]); cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal);
// // n to go to next/N to go to previous // n to go to next/N to go to previous
// cx.simulate_keystrokes(["n"]); cx.simulate_keystrokes(["n"]);
// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal);
// cx.simulate_keystrokes(["shift-n"]); cx.simulate_keystrokes(["shift-n"]);
// cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal); cx.assert_state("aa\nbb\nˇcc\ncc\ncc\n", Mode::Normal);
// // ?<enter> to go to previous // ?<enter> to go to previous
// cx.simulate_keystrokes(["?", "enter"]); cx.simulate_keystrokes(["?", "enter"]);
// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal);
// cx.simulate_keystrokes(["?", "enter"]); cx.simulate_keystrokes(["?", "enter"]);
// cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal); cx.assert_state("aa\nbb\ncc\nˇcc\ncc\n", Mode::Normal);
// // /<enter> to go to next // /<enter> to go to next
// cx.simulate_keystrokes(["/", "enter"]); cx.simulate_keystrokes(["/", "enter"]);
// cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal); cx.assert_state("aa\nbb\ncc\ncc\nˇcc\n", Mode::Normal);
// // ?{search}<enter> to search backwards // ?{search}<enter> to search backwards
// cx.simulate_keystrokes(["?", "b", "enter"]); cx.simulate_keystrokes(["?", "b", "enter"]);
// cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal); cx.assert_state("aa\nbˇb\ncc\ncc\ncc\n", Mode::Normal);
// // works with counts // works with counts
// cx.simulate_keystrokes(["4", "/", "c"]); cx.simulate_keystrokes(["4", "/", "c"]);
// cx.simulate_keystrokes(["enter"]); cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal); cx.assert_state("aa\nbb\ncc\ncˇc\ncc\n", Mode::Normal);
// // check that searching resumes from cursor, not previous match // check that searching resumes from cursor, not previous match
// cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); cx.set_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal);
// cx.simulate_keystrokes(["/", "d"]); cx.simulate_keystrokes(["/", "d"]);
// cx.simulate_keystrokes(["enter"]); cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nbb\nˇdd\ncc\nbb\n", Mode::Normal); 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.update_editor(|editor, cx| editor.move_to_beginning(&Default::default(), cx));
// cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal); cx.assert_state("ˇaa\nbb\ndd\ncc\nbb\n", Mode::Normal);
// cx.simulate_keystrokes(["/", "b"]); cx.simulate_keystrokes(["/", "b"]);
// cx.simulate_keystrokes(["enter"]); cx.simulate_keystrokes(["enter"]);
// cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal); cx.assert_state("aa\nˇbb\ndd\ncc\nbb\n", Mode::Normal);
// } }
// #[gpui::test] #[gpui::test]
// async fn test_non_vim_search(cx: &mut gpui::TestAppContext) { async fn test_non_vim_search(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, false).await; let mut cx = VimTestContext::new(cx, false).await;
// cx.set_state("ˇone one one one", Mode::Normal); cx.set_state("ˇone one one one", Mode::Normal);
// cx.simulate_keystrokes(["cmd-f"]); cx.simulate_keystrokes(["cmd-f"]);
// cx.run_until_parked(); cx.run_until_parked();
// cx.assert_editor_state("«oneˇ» one one one"); cx.assert_editor_state("«oneˇ» one one one");
// cx.simulate_keystrokes(["enter"]); cx.simulate_keystrokes(["enter"]);
// cx.assert_editor_state("one «oneˇ» one one"); cx.assert_editor_state("one «oneˇ» one one");
// cx.simulate_keystrokes(["shift-enter"]); cx.simulate_keystrokes(["shift-enter"]);
// cx.assert_editor_state("«oneˇ» one one one"); cx.assert_editor_state("«oneˇ» one one one");
// } }
// } }

View file

@ -26,7 +26,7 @@ theme_selector = { package = "theme_selector2", path = "../theme_selector2" }
util = { path = "../util" } util = { path = "../util" }
picker = { package = "picker2", path = "../picker2" } picker = { package = "picker2", path = "../picker2" }
workspace = { package = "workspace2", path = "../workspace2" } workspace = { package = "workspace2", path = "../workspace2" }
# vim = { package = "vim2", path = "../vim2" } vim = { package = "vim2", path = "../vim2" }
anyhow.workspace = true anyhow.workspace = true
log.workspace = true log.workspace = true

View file

@ -11,6 +11,7 @@ use gpui::{
use settings::{Settings, SettingsStore}; use settings::{Settings, SettingsStore};
use std::sync::Arc; use std::sync::Arc;
use ui::{prelude::*, Checkbox}; use ui::{prelude::*, Checkbox};
use vim::VimModeSetting;
use workspace::{ use workspace::{
dock::DockPosition, dock::DockPosition,
item::{Item, ItemEvent}, item::{Item, ItemEvent},
@ -128,29 +129,26 @@ impl Render for WelcomePage {
.border_color(cx.theme().colors().border) .border_color(cx.theme().colors().border)
.rounded_md() .rounded_md()
.child( .child(
// todo!("vim setting")
h_stack() h_stack()
.gap_2() .gap_2()
.child( .child(
Checkbox::new( Checkbox::new(
"enable-vim", "enable-vim",
if false if VimModeSetting::get_global(cx).0 {
/* VimSettings::get_global(cx).enabled */
{
ui::Selection::Selected ui::Selection::Selected
} else { } else {
ui::Selection::Unselected ui::Selection::Unselected
}, },
), )
// .on_click(cx.listener( .on_click(cx.listener(
// move |this, selection, cx| { move |this, selection, cx| {
// this.update_settings::<VimSettings>( this.update_settings::<VimModeSetting>(
// selection, selection,
// cx, cx,
// |settings, value| settings.enabled = value, |setting, value| *setting = Some(value),
// ); );
// }, },
// )), )),
) )
.child(Label::new("Enable vim mode")), .child(Label::new("Enable vim mode")),
) )