Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Don't let focus follows mouse steal focus from single-line inputs (#66167)
Smit Barmase60919b0248d6
diff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rsindex a2bd6567831..6baec76e4d6 100644--- a/crates/project_panel/src/project_panel_tests.rs+++ b/crates/project_panel/src/project_panel_tests.rs@@ -12839,6 +12839,52 @@ async fn test_focus_follows_mouse_into_blank_area(cx: &mut gpui::TestAppContext)});}+#[gpui::test]+async fn test_focus_follows_mouse_keeps_rename_editor_focused(cx: &mut gpui::TestAppContext) {+ init_test_with_editor(cx);+ cx.update(|cx| {+ cx.update_global::<SettingsStore, _>(|store, cx| {+ store.update_user_settings(cx, |settings| {+ settings.workspace.focus_follows_mouse = Some(settings::FocusFollowsMouse {+ enabled: Some(true),+ debounce_ms: Some(100),+ });+ });+ });+ });++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree(path!("/root"), json!({ "a.txt": "" })).await;++ let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;+ let window = cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));+ let workspace = window+ .read_with(cx, |mw, _| mw.workspace().clone())+ .unwrap();+ let cx = &mut VisualTestContext::from_window(window.into(), cx);+ let panel = workspace.update_in(cx, |workspace, window, cx| {+ let panel = ProjectPanel::new(workspace, window, cx);+ workspace.add_panel(panel.clone(), window, cx);+ workspace.open_panel::<ProjectPanel>(window, cx);+ panel+ });+ cx.run_until_parked();++ select_path(&panel, "root/a.txt", cx);+ panel.update_in(cx, |panel, window, cx| panel.rename(&Rename, window, cx));+ cx.run_until_parked();++ cx.simulate_mouse_move(point(px(1800.), px(600.)), None, Modifiers::none());+ cx.executor().advance_clock(Duration::from_millis(200));+ cx.run_until_parked();++ assert_eq!(+ visible_entries_as_strings(&panel, 0..10, cx),+ &["v root", " [EDITOR: 'a.txt'] <== selected"],+ "Hovering the project panel should not cancel the rename"+ );+}+pub(crate) fn init_test(cx: &mut TestAppContext) {cx.update(|cx| {let settings_store = SettingsStore::test(cx);diff --git a/crates/workspace/src/focus_follows_mouse.rs b/crates/workspace/src/focus_follows_mouse.rsindex da433cefcf0..06f3f9dd5da 100644--- a/crates/workspace/src/focus_follows_mouse.rs+++ b/crates/workspace/src/focus_follows_mouse.rs@@ -1,6 +1,6 @@use gpui::{AnyWindowHandle, AppContext as _, Context, FocusHandle, Focusable, Global,- StatefulInteractiveElement, Task,+ StatefulInteractiveElement, Task, Window,};use crate::workspace_settings;@@ -51,6 +51,9 @@ pub trait FocusFollowsMouse<E: Focusable>: StatefulInteractiveElement {};let _ = cx.update_window(window, move |_view, window, cx| {+ if is_single_line_editor_focused(window) {+ return;+ }window.focus(&focus, cx);});});@@ -69,3 +72,12 @@ pub trait FocusFollowsMouse<E: Focusable>: StatefulInteractiveElement {}impl<E: Focusable, T: StatefulInteractiveElement> FocusFollowsMouse<E> for T {}++fn is_single_line_editor_focused(window: &Window) -> bool {+ window.context_stack().last().is_some_and(|context| {+ context.contains("Editor")+ && context+ .get("mode")+ .is_some_and(|mode| mode.as_ref() == "single_line")+ })+}