Reduce amount of workspace serialization happening (#22730)

Part of https://github.com/zed-industries/zed/issues/16472

Reduces amount of workspace serialization happening by:
* fixing the deserialization logic: now it does not set panels that are
hidden to active
* cleaning up `active_panel_index` for docks that are closed, to avoid
emitting extra events for such closed docks
* adjusting outline panel to drop active editor subscriptions on
deactivation — this way, `cx.observe` on the dock with outline panel is
not triggered (used to be triggered on every selection change before)
* adjusting workspace dock drag listener to remember previous
coordinates and only resize the dock if those had changed
* adjusting workspace pane event listener to ignore
`pane::Event::UserSavedItem` and `pane::Event::ChangeItemTitle` that
seem to happen relatively frequently but not influence values that are
serialized for the workspace
* not using `cx.observe` on docks, instead explicitly serializing on
panel zoom and size changes

Release Notes:

- Reduced amount of workspace serialization happening
This commit is contained in:
Kirill Bulatov 2025-01-07 13:00:26 +02:00 committed by GitHub
parent 4c47728d6f
commit a827f54022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 101 additions and 66 deletions

View file

@ -170,6 +170,7 @@ impl From<&dyn PanelHandle> for AnyView {
pub struct Dock {
position: DockPosition,
panel_entries: Vec<PanelEntry>,
workspace: WeakView<Workspace>,
is_open: bool,
active_panel_index: Option<usize>,
focus_handle: FocusHandle,
@ -236,6 +237,7 @@ impl Dock {
});
Self {
position,
workspace: workspace.downgrade(),
panel_entries: Default::default(),
active_panel_index: None,
is_open: false,
@ -337,6 +339,9 @@ impl Dock {
self.is_open = open;
if let Some(active_panel) = self.active_panel_entry() {
active_panel.panel.set_active(open, cx);
if !open {
self.active_panel_index = None;
}
}
cx.notify();
@ -354,6 +359,11 @@ impl Dock {
}
}
self.workspace
.update(cx, |workspace, cx| {
workspace.serialize_workspace(cx);
})
.ok();
cx.notify();
}
@ -484,7 +494,8 @@ impl Dock {
},
);
if !self.restore_state(cx) && panel.read(cx).starts_open(cx) {
self.restore_state(cx);
if panel.read(cx).starts_open(cx) {
self.activate_panel(index, cx);
self.set_open(true, cx);
}
@ -652,9 +663,14 @@ impl Render for Dock {
)
.on_mouse_up(
MouseButton::Left,
cx.listener(|v, e: &MouseUpEvent, cx| {
cx.listener(|dock, e: &MouseUpEvent, cx| {
if e.click_count == 2 {
v.resize_active_panel(None, cx);
dock.resize_active_panel(None, cx);
dock.workspace
.update(cx, |workspace, cx| {
workspace.serialize_workspace(cx);
})
.ok();
cx.stop_propagation();
}
}),