Fix panel state (#13668)
In the latest update, panel loading occasionally occurred randomly, either before or after workspace deserialization due to their asynchronous nature. This update addresses the issue by ensuring panels restore their state based on serialized data, synchronizing their loading with workspace deserialization. Release Notes: - Fixed [#9638](https://github.com/zed-industries/zed/issues/9638) - Fixed [#12954](https://github.com/zed-industries/zed/issues/12954)
This commit is contained in:
parent
52583fe1ed
commit
ed09bb949c
2 changed files with 33 additions and 27 deletions
|
@ -431,25 +431,12 @@ impl Dock {
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
let name = panel.persistent_name().to_string();
|
|
||||||
|
|
||||||
self.panel_entries.push(PanelEntry {
|
self.panel_entries.push(PanelEntry {
|
||||||
panel: Arc::new(panel.clone()),
|
panel: Arc::new(panel.clone()),
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
});
|
});
|
||||||
if let Some(serialized) = self.serialized_dock.clone() {
|
|
||||||
if serialized.active_panel == Some(name) {
|
if !self.restore_state(cx) && panel.read(cx).starts_open(cx) {
|
||||||
self.activate_panel(self.panel_entries.len() - 1, cx);
|
|
||||||
if serialized.visible {
|
|
||||||
self.set_open(true, cx);
|
|
||||||
}
|
|
||||||
if serialized.zoom {
|
|
||||||
if let Some(panel) = self.active_panel() {
|
|
||||||
panel.set_zoomed(true, cx)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if panel.read(cx).starts_open(cx) {
|
|
||||||
self.activate_panel(self.panel_entries.len() - 1, cx);
|
self.activate_panel(self.panel_entries.len() - 1, cx);
|
||||||
self.set_open(true, cx);
|
self.set_open(true, cx);
|
||||||
}
|
}
|
||||||
|
@ -457,6 +444,25 @@ impl Dock {
|
||||||
cx.notify()
|
cx.notify()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn restore_state(&mut self, cx: &mut ViewContext<Self>) -> bool {
|
||||||
|
if let Some(serialized) = self.serialized_dock.clone() {
|
||||||
|
if let Some(active_panel) = serialized.active_panel {
|
||||||
|
if let Some(idx) = self.panel_index_for_persistent_name(active_panel.as_str(), cx) {
|
||||||
|
self.activate_panel(idx, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if serialized.zoom {
|
||||||
|
if let Some(panel) = self.active_panel() {
|
||||||
|
panel.set_zoomed(true, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.set_open(serialized.visible, cx);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
|
pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(panel_ix) = self
|
if let Some(panel_ix) = self
|
||||||
.panel_entries
|
.panel_entries
|
||||||
|
|
|
@ -3813,18 +3813,18 @@ impl Workspace {
|
||||||
|
|
||||||
let docks = serialized_workspace.docks;
|
let docks = serialized_workspace.docks;
|
||||||
|
|
||||||
let right = docks.right.clone();
|
for (dock, serialized_dock) in [
|
||||||
workspace
|
(&mut workspace.right_dock, docks.right),
|
||||||
.right_dock
|
(&mut workspace.left_dock, docks.left),
|
||||||
.update(cx, |dock, _| dock.serialized_dock = Some(right));
|
(&mut workspace.bottom_dock, docks.bottom),
|
||||||
let left = docks.left.clone();
|
]
|
||||||
workspace
|
.iter_mut()
|
||||||
.left_dock
|
{
|
||||||
.update(cx, |dock, _| dock.serialized_dock = Some(left));
|
dock.update(cx, |dock, cx| {
|
||||||
let bottom = docks.bottom.clone();
|
dock.serialized_dock = Some(serialized_dock.clone());
|
||||||
workspace
|
dock.restore_state(cx);
|
||||||
.bottom_dock
|
});
|
||||||
.update(cx, |dock, _| dock.serialized_dock = Some(bottom));
|
}
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue