Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Don't cancel renames or dismiss Go to Line when the window is deactivated (#61852)
Mikhail Butvinb005c0de6728
diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rsindex 5a52afc7cbe..3e3201f8101 100644--- a/crates/collab_ui/src/collab_panel.rs+++ b/crates/collab_ui/src/collab_panel.rs@@ -396,7 +396,9 @@ impl CollabPanel {&channel_name_editor,window,|this: &mut Self, _, event, window, cx| {- if let editor::EditorEvent::Blurred = event {+ if let editor::EditorEvent::Blurred = event+ && window.is_window_active()+ {if let Some(state) = &this.channel_editing_state&& state.pending_name().is_some(){diff --git a/crates/go_to_line/src/go_to_line.rs b/crates/go_to_line/src/go_to_line.rsindex de80a5af01d..48017a6e6a6 100644--- a/crates/go_to_line/src/go_to_line.rs+++ b/crates/go_to_line/src/go_to_line.rs@@ -166,11 +166,11 @@ impl GoToLine {&mut self,_: &Entity<Editor>,event: &editor::EditorEvent,- _window: &mut Window,+ window: &mut Window,cx: &mut Context<Self>,) {match event {- editor::EditorEvent::Blurred => {+ editor::EditorEvent::Blurred if window.is_window_active() => {self.prev_scroll_position.take();cx.emit(DismissEvent)}diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex 1dcb28933b5..9f79115d282 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -778,7 +778,7 @@ impl ProjectPanel {EditorEvent::SelectionsChanged { .. } => {project_panel.autoscroll(cx);}- EditorEvent::Blurred => {+ EditorEvent::Blurred if window.is_window_active() => {if project_panel.state.edit_statediff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rsindex 0ab83a1cd3d..64285792d75 100644--- a/crates/project_panel/src/project_panel_tests.rs+++ b/crates/project_panel/src/project_panel_tests.rs@@ -4563,6 +4563,38 @@ async fn test_drag_including_worktree_root_only_reorders(cx: &mut gpui::TestAppC);}+#[gpui::test]+async fn test_rename_survives_window_deactivation(cx: &mut gpui::TestAppContext) {+ init_test_with_editor(cx);++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree("/root", json!({ "file1.txt": "content" }))+ .await;++ let project = Project::test(fs.clone(), ["/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, ProjectPanel::new);+ cx.run_until_parked();++ select_path(&panel, "root/file1.txt", cx);+ panel.update_in(cx, |panel, window, cx| panel.rename(&Rename, window, cx));+ assert!(+ panel.read_with(cx, |panel, _| panel.state.edit_state.is_some()),+ "Rename should have started"+ );++ cx.deactivate_window();++ assert!(+ panel.read_with(cx, |panel, _| panel.state.edit_state.is_some()),+ "Rename should not be cancelled when the window is deactivated, e.g. by a keyboard layout switcher grabbing keyboard focus"+ );+}+#[gpui::test]async fn test_multiple_marked_entries(cx: &mut gpui::TestAppContext) {init_test_with_editor(cx);