Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Fix panel buttons not working while a dock panel is zoomed (#66119)
yaroslav5e548b8ad99c
diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rsindex 386667e3f6c..60ba69dacc4 100644--- a/crates/workspace/src/dock.rs+++ b/crates/workspace/src/dock.rs@@ -989,6 +989,14 @@ impl Dock {}}+ /// Panel buttons focus this before dispatching their action. A zoomed panel isn't rendered+ /// inside its dock, so the dock's own handle would be outside the frame and the action dropped.+ pub(crate) fn panel_button_focus_handle(&self, window: &Window, cx: &App) -> FocusHandle {+ self.zoomed_panel(window, cx)+ .map(|panel| panel.panel_focus_handle(cx))+ .unwrap_or_else(|| self.focus_handle.clone())+ }+pub fn active_panel_size(&self) -> Option<PanelSizeState> {if self.is_open {self.active_panel_entry().map(|entry| entry.size_state)@@ -1435,7 +1443,7 @@ impl Render for PanelButtons {(action, icon_tooltip.into())};- let focus_handle = dock.focus_handle(cx);+ let focus_handle = dock.panel_button_focus_handle(window, cx);let icon_label = entry.panel.icon_label(window, cx);Some(diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex ad224f2e4ee..b4a687c8847 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -12723,8 +12723,8 @@ mod tests {};use fs::{FakeFs, RemoveOptions};use gpui::{- DismissEvent, Empty, EventEmitter, FocusHandle, Focusable, Render, TestAppContext,- UpdateGlobal, VisualTestContext, px,+ DismissEvent, Empty, EventEmitter, FocusHandle, Focusable, Modifiers, Render,+ TestAppContext, UpdateGlobal, VisualTestContext, px,};use project::{Project, ProjectEntryId, WorktreeId};use serde_json::json;@@ -20753,6 +20753,77 @@ mod tests {});}+ #[gpui::test]+ async fn test_panel_buttons_work_while_dock_is_zoomed(cx: &mut gpui::TestAppContext) {+ init_test(cx);+ let fs = FakeFs::new(cx.executor());+ let project = Project::test(fs, [], cx).await;+ // Workspace actions are registered on the `MultiWorkspace` root, so a bare `Workspace`+ // window wouldn't route dispatched actions to the workspace.+ let (multi_workspace, cx) =+ cx.add_window_view(|window, cx| MultiWorkspace::test_new(project, window, cx));+ let workspace =+ multi_workspace.read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone());++ let (zoomed_panel, sibling_panel) = workspace.update_in(cx, |workspace, window, cx| {+ workspace.register_action(|workspace, _: &ToggleSecondTestPanel, window, cx| {+ workspace.toggle_panel_focus::<SecondTestPanel>(window, cx);+ });+ let sibling_panel = cx.new(|cx| SecondTestPanel {+ focus_handle: cx.focus_handle(),+ zoomed: false,+ });+ workspace.add_panel(sibling_panel.clone(), window, cx);+ let zoomed_panel = cx.new(|cx| TestPanel::new(DockPosition::Bottom, 100, cx));+ workspace.add_panel(zoomed_panel.clone(), window, cx);+ workspace.toggle_panel_focus::<TestPanel>(window, cx);+ (zoomed_panel, sibling_panel)+ });+ zoomed_panel.update(cx, |_, cx| cx.emit(PanelEvent::ZoomIn));+ cx.run_until_parked();+ workspace.read_with(cx, |workspace, _| {+ assert_eq!(workspace.zoomed_position, Some(DockPosition::Bottom));+ });++ let sibling_button = cx+ .debug_bounds("ICON-Terminal")+ .expect("sibling panel button should be rendered in the status bar");+ cx.simulate_click(sibling_button.center(), Modifiers::none());+ cx.run_until_parked();+ workspace.update_in(cx, |workspace, window, cx| {+ let dock = workspace.bottom_dock().read(cx);+ assert!(dock.is_open());+ assert_eq!(+ dock.active_panel().map(|panel| panel.panel_id()),+ Some(sibling_panel.entity_id()),+ );+ assert!(+ sibling_panel+ .read(cx)+ .focus_handle(cx)+ .contains_focused(window, cx)+ );+ });++ sibling_panel.update(cx, |_, cx| cx.emit(PanelEvent::ZoomIn));+ cx.run_until_parked();+ workspace.read_with(cx, |workspace, _| {+ assert_eq!(workspace.zoomed_position, Some(DockPosition::Bottom));+ });++ let close_button = cx+ .debug_bounds("ICON-Terminal")+ .expect("active panel button should be rendered in the status bar");+ cx.simulate_click(close_button.center(), Modifiers::none());+ cx.run_until_parked();+ workspace.read_with(cx, |workspace, cx| {+ assert!(!workspace.bottom_dock().read(cx).is_open());+ assert_eq!(workspace.zoomed_position, None);+ });+ }++ actions!(test_only, [ToggleSecondTestPanel]);+struct SecondTestPanel {focus_handle: FocusHandle,zoomed: bool,@@ -20798,15 +20869,15 @@ mod tests {}fn icon(&self, _: &Window, _: &App) -> Option<ui::IconName> {- None+ Some(ui::IconName::Terminal)}fn icon_tooltip(&self, _: &Window, _: &App) -> Option<&'static str> {- None+ Some("Second Test Panel")}fn toggle_action(&self) -> Box<dyn Action> {- crate::dock::test::ToggleTestPanel.boxed_clone()+ ToggleSecondTestPanel.boxed_clone()}fn activation_priority(&self) -> u32 {