diff --git a/crates/ui/src/dock/mod.rs b/crates/ui/src/dock/mod.rs index d0dd3860..bc581d5f 100644 --- a/crates/ui/src/dock/mod.rs +++ b/crates/ui/src/dock/mod.rs @@ -202,36 +202,6 @@ impl DockArea { /// Subscribe event on the panels #[allow(clippy::only_used_in_recursion)] fn subscribe_item(&self, item: &DockItem, cx: &mut ViewContext) { - /// Subscribe zoom event on the panel - fn subscribe_zoom(view: &View

, cx: &mut ViewContext) { - cx.subscribe(view, move |_, panel, event, cx| match event { - PanelEvent::ZoomIn => { - let dock_area = cx.view().clone(); - let panel = panel.clone(); - cx.spawn(|_, mut cx| async move { - let _ = cx.update(|cx| { - let _ = dock_area.update(cx, |dock, cx| { - dock.set_zoomed_in(panel, cx); - cx.notify(); - }); - }); - }) - .detach(); - } - PanelEvent::ZoomOut => { - let dock_area = cx.view().clone(); - cx.spawn(|_, mut cx| async move { - let _ = cx.update(|cx| { - let _ = dock_area.update(cx, |view, cx| view.set_zoomed_out(cx)); - }); - }) - .detach() - } - PanelEvent::LayoutChanged => cx.emit(DockEvent::LayoutChanged), - }) - .detach(); - } - match item { DockItem::Split { items, view, .. } => { for item in items { @@ -244,14 +214,42 @@ impl DockArea { }) .detach(); } - DockItem::Tabs { view, .. } => { - // We need, only subscribe to the zoom events on the TabPanel - // Because we always wrap the DockItem::Panel in a DockItem::Tabs - subscribe_zoom(view, cx); + DockItem::Tabs { .. } => { + // We subscribe the tab panel event is in StackPanel insert_panel } } } + /// Subscribe zoom event on the panel + pub(crate) fn subscribe_panel(view: &View

, cx: &mut ViewContext) { + cx.subscribe(view, move |_, panel, event, cx| match event { + PanelEvent::ZoomIn => { + let dock_area = cx.view().clone(); + let panel = panel.clone(); + cx.spawn(|_, mut cx| async move { + let _ = cx.update(|cx| { + let _ = dock_area.update(cx, |dock, cx| { + dock.set_zoomed_in(panel, cx); + cx.notify(); + }); + }); + }) + .detach(); + } + PanelEvent::ZoomOut => { + let dock_area = cx.view().clone(); + cx.spawn(|_, mut cx| async move { + let _ = cx.update(|cx| { + let _ = dock_area.update(cx, |view, cx| view.set_zoomed_out(cx)); + }); + }) + .detach() + } + PanelEvent::LayoutChanged => cx.emit(DockEvent::LayoutChanged), + }) + .detach(); + } + /// Returns the ID of the dock area. pub fn id(&self) -> SharedString { self.id.clone() diff --git a/crates/ui/src/dock/stack_panel.rs b/crates/ui/src/dock/stack_panel.rs index de7d7c22..7fb74575 100644 --- a/crates/ui/src/dock/stack_panel.rs +++ b/crates/ui/src/dock/stack_panel.rs @@ -163,7 +163,7 @@ impl StackPanel { panel: Arc, ix: usize, size: Option, - _dock_area: WeakView, + dock_area: WeakView, cx: &mut ViewContext, ) { // If the panel is already in the stack, return. @@ -185,6 +185,13 @@ impl StackPanel { } }); + // Subscribe to the panel's layout change event. + _ = dock_area.update(cx, |_, cx| { + if let Ok(tab_panel) = panel.view().downcast::() { + DockArea::subscribe_panel(&tab_panel, cx); + } + }); + let ix = if ix > self.panels.len() { self.panels.len() } else { diff --git a/crates/ui/src/dock/tab_panel.rs b/crates/ui/src/dock/tab_panel.rs index 9eee596d..57cdb50a 100644 --- a/crates/ui/src/dock/tab_panel.rs +++ b/crates/ui/src/dock/tab_panel.rs @@ -581,12 +581,12 @@ impl TabPanel { } fn on_action_toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext) { - self.is_zoomed = !self.is_zoomed; - if self.is_zoomed { + if !self.is_zoomed { cx.emit(PanelEvent::ZoomIn) } else { cx.emit(PanelEvent::ZoomOut) } + self.is_zoomed = !self.is_zoomed; } fn on_action_close_panel(&mut self, _: &ClosePanel, cx: &mut ViewContext) {