diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 303f591d56..1cb3ace4ac 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -3690,6 +3690,18 @@ impl Sidebar { .detach_and_log_err(cx); } + fn is_thread_active_in_workspace( + &self, + thread_id: &ThreadId, + workspace: &Entity, + cx: &App, + ) -> bool { + self.active_workspace(cx).as_ref() == Some(workspace) + && self.active_entry.as_ref().is_some_and(|entry| { + entry.is_active_thread(thread_id) && entry.workspace() == workspace + }) + } + fn activate_thread_locally( &mut self, metadata: &ThreadMetadata, @@ -3702,6 +3714,13 @@ impl Sidebar { return; }; + if self.is_thread_active_in_workspace(&metadata.thread_id, workspace, cx) { + workspace.update(cx, |workspace, cx| { + workspace.focus_panel::(window, cx); + }); + return; + } + // Set active_entry eagerly so the sidebar highlight updates // immediately, rather than waiting for a deferred AgentPanel // event which can race with ActiveWorkspaceChanged clearing it.