diff --git a/Cargo.lock b/Cargo.lock index 1e22da76f053b75b897c6d7079a724a9efe5704a..edd1676c5834fc299e4071148e3042f5f23af76b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16092,7 +16092,6 @@ dependencies = [ "theme_settings", "ui", "util", - "vim_mode_setting", "workspace", "zed_actions", ] diff --git a/crates/sidebar/Cargo.toml b/crates/sidebar/Cargo.toml index c0c0b26e1dfe2daa8bfa6f2cc7445def417ff177..97e0943980006757d96f97dee68597ef7adfb714 100644 --- a/crates/sidebar/Cargo.toml +++ b/crates/sidebar/Cargo.toml @@ -44,7 +44,6 @@ theme.workspace = true theme_settings.workspace = true ui.workspace = true util.workspace = true -vim_mode_setting.workspace = true workspace.workspace = true zed_actions.workspace = true diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 289a24619636e906d2e065ee18f57b45a01fb5a0..ad03949035a1e91956db43e4d5345e3a36c7ea16 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -485,7 +485,6 @@ impl Sidebar { let filter_editor = cx.new(|cx| { let mut editor = Editor::single_line(window, cx); - editor.set_use_modal_editing(true); editor.set_placeholder_text("Search…", window, cx); editor }); @@ -2213,6 +2212,23 @@ impl Sidebar { } fn cancel(&mut self, _: &Cancel, window: &mut Window, cx: &mut Context) { + if self.filter_editor.read(cx).is_focused(window) { + if self.reset_filter_editor_text(window, cx) { + self.selection = None; + self.update_entries(cx); + return; + } + + if self.selection.is_none() { + self.select_first_entry(); + } + if self.selection.is_some() { + self.focus_handle.focus(window, cx); + cx.notify(); + } + return; + } + if self.reset_filter_editor_text(window, cx) { self.update_entries(cx); } else { @@ -2238,15 +2254,6 @@ impl Sidebar { self.filter_editor.focus_handle(cx).focus(window, cx); } - // When vim mode is active, the editor defaults to normal mode which - // blocks text input. Switch to insert mode so the user can type - // immediately. - if vim_mode_setting::VimModeSetting::get_global(cx).0 { - if let Ok(action) = cx.build_action("vim::SwitchToInsertMode", None) { - window.dispatch_action(action, cx); - } - } - cx.notify(); } diff --git a/crates/sidebar/src/sidebar_tests.rs b/crates/sidebar/src/sidebar_tests.rs index 7600793dff500cde8d8e54d86186e26e3816a923..2de895114d1ca3082592a6a8359951d69f180a61 100644 --- a/crates/sidebar/src/sidebar_tests.rs +++ b/crates/sidebar/src/sidebar_tests.rs @@ -1679,9 +1679,9 @@ async fn test_search_matches_regardless_of_case(cx: &mut TestAppContext) { } #[gpui::test] -async fn test_escape_clears_search_and_restores_full_list(cx: &mut TestAppContext) { +async fn test_escape_from_search_focuses_first_thread(cx: &mut TestAppContext) { // Scenario: A user searches, finds what they need, then presses Escape - // to dismiss the filter and see the full list again. + // in the search field to hand keyboard control back to the thread list. let project = init_test_project("/my-project", cx).await; let (multi_workspace, cx) = cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx)); @@ -1723,8 +1723,8 @@ async fn test_escape_clears_search_and_restores_full_list(cx: &mut TestAppContex ] ); - // User presses Escape — filter clears, full list is restored. - // The selection index (1) now points at the first thread entry. + // First Escape clears the search text, restoring the full list. + // Focus stays on the filter editor. cx.dispatch_action(Cancel); cx.run_until_parked(); assert_eq!( @@ -1732,10 +1732,23 @@ async fn test_escape_clears_search_and_restores_full_list(cx: &mut TestAppContex vec![ // "v [my-project]", - " Alpha thread <== selected", + " Alpha thread", " Beta thread", ] ); + sidebar.update_in(cx, |sidebar, window, cx| { + assert!(sidebar.filter_editor.read(cx).is_focused(window)); + assert!(!sidebar.focus_handle.is_focused(window)); + }); + + // Second Escape moves focus from the empty search field to the thread list. + cx.dispatch_action(Cancel); + cx.run_until_parked(); + sidebar.update_in(cx, |sidebar, window, cx| { + assert_eq!(sidebar.selection, Some(1)); + assert!(sidebar.focus_handle.is_focused(window)); + assert!(!sidebar.filter_editor.read(cx).is_focused(window)); + }); } #[gpui::test]