Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Activate the correct panel when deserializing workspace
Antonio Scandurra3d6b7283647e
diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rsindex 5c501f64ad1..e115e1d5739 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<T: Panel>(&self) -> Option<usize> {+ pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {self.panel_entries.iter().position(|entry| entry.panel.as_any().is::<T>())}+ pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {+ 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.rsindex 30a2a2f4e32..01ed898de4c 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -1480,7 +1480,7 @@ impl Workspace {pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {- if let Some(panel_index) = dock.read(cx).panel_index::<T>() {+ if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {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();