Close keyboard gap in New Thread Clicked telemetry

Katie Geer created

Previously the event only fired when the + dropdown menu was opened
(mouse path). The NewThread keyboard shortcut bypassed the menu builder
and called new_thread directly, producing no event.

Approach:
- Extract new_thread body into a private do_new_thread helper.
- new_thread (action handler / keyboard shortcut) fires the event with
  source='agent_panel' then delegates to do_new_thread.
- new_thread_from_sidebar (pub, for the sidebar crate) fires the event
  with source='sidebar' then delegates to do_new_thread.
- Both sidebar call sites (mouse click via create_new_thread and keyboard
  confirm in the list) now call new_thread_from_sidebar, eliminating the
  double-fire that would have occurred if the panel's own new_thread
  were called after the sidebar had already fired the event.

Change summary

crates/agent_ui/src/agent_panel.rs | 28 ++++++++++++++++++++++++++++
crates/sidebar/src/sidebar.rs      | 24 +++++-------------------
2 files changed, 33 insertions(+), 19 deletions(-)

Detailed changes

crates/agent_ui/src/agent_panel.rs 🔗

@@ -1304,6 +1304,34 @@ impl AgentPanel {
     }
 
     pub fn new_thread(&mut self, _action: &NewThread, window: &mut Window, cx: &mut Context<Self>) {
+        use settings::{NewThreadLocation, Settings};
+        let thread_location = match AgentSettings::get_global(cx).new_thread_location {
+            NewThreadLocation::LocalProject => "current_worktree",
+            NewThreadLocation::NewWorktree => "new_worktree",
+        };
+        telemetry::event!(
+            "New Thread Clicked",
+            source = "agent_panel",
+            thread_location = thread_location
+        );
+        self.do_new_thread(window, cx);
+    }
+
+    pub fn new_thread_from_sidebar(&mut self, window: &mut Window, cx: &mut Context<Self>) {
+        use settings::{NewThreadLocation, Settings};
+        let thread_location = match AgentSettings::get_global(cx).new_thread_location {
+            NewThreadLocation::LocalProject => "current_worktree",
+            NewThreadLocation::NewWorktree => "new_worktree",
+        };
+        telemetry::event!(
+            "New Thread Clicked",
+            source = "sidebar",
+            thread_location = thread_location
+        );
+        self.do_new_thread(window, cx);
+    }
+
+    fn do_new_thread(&mut self, window: &mut Window, cx: &mut Context<Self>) {
         self.reset_start_thread_in_to_default(cx);
         let initial_content = self.take_active_draft_initial_content(cx);
         self.external_thread(None, None, None, None, initial_content, true, window, cx);

crates/sidebar/src/sidebar.rs 🔗

@@ -9,9 +9,7 @@ use agent_ui::threads_archive_view::{
     ThreadsArchiveView, ThreadsArchiveViewEvent, format_history_entry_timestamp,
 };
 use agent_ui::{AcpThreadImportOnboarding, ThreadImportModal};
-use agent_ui::{
-    Agent, AgentPanel, AgentPanelEvent, DEFAULT_THREAD_TITLE, NewThread, RemoveSelectedThread,
-};
+use agent_ui::{Agent, AgentPanel, AgentPanelEvent, DEFAULT_THREAD_TITLE, RemoveSelectedThread};
 use chrono::{DateTime, Utc};
 use editor::Editor;
 use gpui::{
@@ -30,7 +28,7 @@ use remote::RemoteConnectionOptions;
 use ui::utils::platform_title_bar_height;
 
 use serde::{Deserialize, Serialize};
-use settings::{NewThreadLocation, Settings as _};
+use settings::Settings as _;
 use std::collections::{HashMap, HashSet};
 use std::mem;
 use std::rc::Rc;
@@ -2531,9 +2529,7 @@ impl Sidebar {
                                 panel.clear_active_thread(window, cx);
                             });
                         }
-                    }
-                }
-            }
+                    });
             return;
         }
 
@@ -2556,7 +2552,7 @@ impl Sidebar {
         if let Some(workspace) = self.active_entry_workspace().cloned() {
             if let Some(panel) = workspace.read(cx).panel::<AgentPanel>(cx) {
                 panel.update(cx, |panel, cx| {
-                    panel.new_thread(&NewThread, window, cx);
+                    panel.new_thread_from_sidebar(window, cx);
                 });
             }
         }
@@ -3171,16 +3167,6 @@ impl Sidebar {
             return;
         };
 
-        let thread_location = match AgentSettings::get_global(cx).new_thread_location {
-            NewThreadLocation::LocalProject => "current_worktree",
-            NewThreadLocation::NewWorktree => "new_worktree",
-        };
-        telemetry::event!(
-            "New Thread Clicked",
-            source = "sidebar",
-            thread_location = thread_location
-        );
-
         self.active_entry = Some(ActiveEntry::Draft(workspace.clone()));
 
         multi_workspace.update(cx, |multi_workspace, cx| {
@@ -3190,7 +3176,7 @@ impl Sidebar {
         workspace.update(cx, |workspace, cx| {
             if let Some(agent_panel) = workspace.panel::<AgentPanel>(cx) {
                 agent_panel.update(cx, |panel, cx| {
-                    panel.new_thread(&NewThread, window, cx);
+                    panel.new_thread_from_sidebar(window, cx);
                 });
             }
             workspace.focus_panel::<AgentPanel>(window, cx);