diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 5c501f64ad..e115e1d573 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -1,8 +1,9 @@ use crate::{StatusItemView, Workspace}; use context_menu::{ContextMenu, ContextMenuItem}; use gpui::{ - elements::*, impl_actions, platform::CursorStyle, platform::MouseButton, AnyViewHandle, Axis, - Entity, Subscription, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext, + elements::*, impl_actions, platform::CursorStyle, platform::MouseButton, AnyViewHandle, + AppContext, Axis, Entity, Subscription, View, ViewContext, ViewHandle, WeakViewHandle, + WindowContext, }; use serde::Deserialize; use settings::Settings; @@ -181,12 +182,19 @@ impl Dock { .map_or(false, |panel| panel.has_focus(cx)) } - pub fn panel_index(&self) -> Option { + pub fn panel_index_for_type(&self) -> Option { self.panel_entries .iter() .position(|entry| entry.panel.as_any().is::()) } + pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option { + self.panel_entries.iter().position(|entry| { + let panel = entry.panel.as_any(); + cx.view_ui_name(panel.window_id(), panel.id()) == Some(ui_name) + }) + } + pub fn active_panel_index(&self) -> usize { self.active_panel_index } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 30a2a2f4e3..01ed898de4 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1480,7 +1480,7 @@ impl Workspace { pub fn toggle_panel_focus(&mut self, cx: &mut ViewContext) { for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { - if let Some(panel_index) = dock.read(cx).panel_index::() { + if let Some(panel_index) = dock.read(cx).panel_index_for_type::() { let active_item = dock.update(cx, |dock, cx| { dock.set_open(true, cx); dock.activate_panel(panel_index, cx); @@ -2605,7 +2605,7 @@ impl Workspace { ) }); - dbg!(DockStructure { + DockStructure { left: DockData { visible: left_visible, active_panel: left_active_panel, @@ -2618,7 +2618,7 @@ impl Workspace { visible: bottom_visible, active_panel: bottom_active_panel, }, - }) + } } if let Some(location) = self.location(cx) { @@ -2691,15 +2691,28 @@ impl Workspace { let docks = serialized_workspace.docks; workspace.left_dock.update(cx, |dock, cx| { - dbg!(docks.left.visible); dock.set_open(docks.left.visible, cx); - dbg!(dock.is_open()); + if let Some(active_panel) = docks.left.active_panel { + if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { + dock.activate_panel(ix, cx); + } + } }); workspace.right_dock.update(cx, |dock, cx| { dock.set_open(docks.right.visible, cx); + if let Some(active_panel) = docks.right.active_panel { + if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { + dock.activate_panel(ix, cx); + } + } }); workspace.bottom_dock.update(cx, |dock, cx| { dock.set_open(docks.bottom.visible, cx); + if let Some(active_panel) = docks.bottom.active_panel { + if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) { + dock.activate_panel(ix, cx); + } + } }); cx.notify();