Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix vim mode in thread sidebar (#54381)

Conrad Irwinb366f8e9d3d3
diff --git a/Cargo.lock b/Cargo.lock
index 5b9676d92f9..553c936cd0a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16169,7 +16169,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 c0c0b26e1df..97e09439800 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 4491c1693d6..55e9b2ddae1 100644
--- a/crates/sidebar/src/sidebar.rs
+++ b/crates/sidebar/src/sidebar.rs
@@ -505,7 +505,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
});
@@ -2222,6 +2221,23 @@ impl Sidebar {
}
fn cancel(&mut self, _: &Cancel, window: &mut Window, cx: &mut Context<Self>) {
+ 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 {
@@ -2247,15 +2263,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 7600793dff5..2de895114d1 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]