diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index b1de240eb62bcca6967333641bf8234825730300..84b86a92ec5bdae9e6184037c8bf25488b308ff0 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1179,6 +1179,7 @@ pub struct Workspace { session_id: Option, scheduled_tasks: Vec>, last_open_dock_positions: Vec, + removing: bool, } impl EventEmitter for Workspace {} @@ -1522,6 +1523,7 @@ impl Workspace { scheduled_tasks: Vec::new(), last_open_dock_positions: Vec::new(), + removing: false, } } @@ -2335,12 +2337,13 @@ impl Workspace { ) -> Task> { let active_call = self.active_call().cloned(); - // On Linux and Windows, closing the last window should restore the last workspace. - let save_last_workspace = cfg!(not(target_os = "macos")) - && close_intent != CloseIntent::ReplaceWindow - && cx.windows().len() == 1; - cx.spawn_in(window, async move |this, cx| { + this.update(cx, |this, _| { + if close_intent == CloseIntent::CloseWindow { + this.removing = true; + } + })?; + let workspace_count = cx.update(|_window, cx| { cx.windows() .iter() @@ -2348,6 +2351,28 @@ impl Workspace { .count() })?; + #[cfg(target_os = "macos")] + let save_last_workspace = false; + + // On Linux and Windows, closing the last window should restore the last workspace. + #[cfg(not(target_os = "macos"))] + let save_last_workspace = { + let remaining_workspaces = cx.update(|_window, cx| { + cx.windows() + .iter() + .filter_map(|window| window.downcast::()) + .filter_map(|workspace| { + workspace + .update(cx, |workspace, _, _| workspace.removing) + .ok() + }) + .filter(|removing| !removing) + .count() + })?; + + close_intent != CloseIntent::ReplaceWindow && remaining_workspaces == 0 + }; + if let Some(active_call) = active_call && workspace_count == 1 && active_call.read_with(cx, |call, _| call.room().is_some())?