From 1b3ff5ea73fc7f5995c1facda59ed942b041bdd2 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Mon, 15 Jun 2026 18:19:16 -0300 Subject: [PATCH] sidebar: Fix click flicker on empty draft thread (#59342) Closes AI-404 This PR fixes a flicker that was happening when clicking on an empty draft thread item in the sidebar, given we were going through the whole regular activation flow despite the thread already being active. So, the fix here was just extracting a boolean so we can identify whether the thread is active in the workspace and if so, not doing nothing in the on_click handler of the thread item. Release Notes: - Sidebar: Fixed a flicker when clicking on an empty draft thread. --- crates/sidebar/src/sidebar.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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.