Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

sidebar: Fix title bar upon moving workspace to a new window (#52266)

Danilo Lealeeafae370b66
diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs
index 9b148a72e94..b013a593c86 100644
--- a/crates/title_bar/src/title_bar.rs
+++ b/crates/title_bar/src/title_bar.rs
@@ -161,6 +161,8 @@ pub struct TitleBar {
impl Render for TitleBar {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
+ self.sync_multi_workspace(window, cx);
+
let title_bar_settings = *TitleBarSettings::get_global(cx);
let button_layout = title_bar_settings.button_layout;
@@ -445,6 +447,46 @@ impl TitleBar {
this
}
+ /// Used to update the title bar state in case the workspace has
+ /// been moved to a new window through the threads sidebar.
+ fn sync_multi_workspace(&mut self, window: &mut Window, cx: &mut Context<Self>) {
+ let current = window
+ .root::<MultiWorkspace>()
+ .flatten()
+ .map(|mw| mw.entity_id());
+
+ let tracked = self
+ .multi_workspace
+ .as_ref()
+ .and_then(|weak| weak.upgrade())
+ .map(|mw| mw.entity_id());
+
+ if current == tracked {
+ return;
+ }
+
+ let Some(multi_workspace) = window.root::<MultiWorkspace>().flatten() else {
+ self.multi_workspace = None;
+ return;
+ };
+
+ let is_open = multi_workspace.read(cx).sidebar_open();
+ self.platform_titlebar.update(cx, |titlebar, cx| {
+ titlebar.set_workspace_sidebar_open(is_open, cx);
+ });
+
+ let platform_titlebar = self.platform_titlebar.clone();
+ let subscription = cx.observe(&multi_workspace, move |_this, mw, cx| {
+ let is_open = mw.read(cx).sidebar_open();
+ platform_titlebar.update(cx, |titlebar, cx| {
+ titlebar.set_workspace_sidebar_open(is_open, cx);
+ });
+ });
+
+ self.multi_workspace = Some(multi_workspace.downgrade());
+ self._subscriptions.push(subscription);
+ }
+
fn worktree_count(&self, cx: &App) -> usize {
self.project.read(cx).visible_worktrees(cx).count()
}