From 9087eed1eff6fd24dd9e130a5bee0c44f68c7423 Mon Sep 17 00:00:00 2001 From: Katie Geer Date: Wed, 1 Apr 2026 12:04:47 -0700 Subject: [PATCH] Close keyboard gap in New Thread Clicked telemetry 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. --- crates/agent_ui/src/agent_panel.rs | 28 ++++++++++++++++++++++++++++ crates/sidebar/src/sidebar.rs | 24 +++++------------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 725b7a9cc24321399c464ee51908916c090e8774..687a9d0fea7d0f063398b9f05a50a192e8e23168 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/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) { + 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) { + 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.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); diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 56e71d4f9818131283b1420cd4e67913cf570f3b..32f084a80f329fa01bd79620b26a8a0fca7c8fa6 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/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::(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::(cx) { agent_panel.update(cx, |panel, cx| { - panel.new_thread(&NewThread, window, cx); + panel.new_thread_from_sidebar(window, cx); }); } workspace.focus_panel::(window, cx);