diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index a511b365632..4cab8aee371 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -3953,6 +3953,14 @@ impl AgentPanel { } } + fn should_show_title_edit(&self, window: &Window, cx: &Context) -> bool { + matches!( + self.visible_surface(), + VisibleSurface::AgentThread(_) | VisibleSurface::Terminal(_) + ) && self.has_open_project(cx) + && !self.is_title_editor_focused(window, cx) + } + fn render_title_view(&self, window: &mut Window, cx: &Context) -> AnyElement { let content = match self.visible_surface() { VisibleSurface::AgentThread(conversation_view) => { @@ -4096,26 +4104,21 @@ impl AgentPanel { .max_w_full() .overflow_x_hidden() .child(content) - .when( - matches!(self.visible_surface(), VisibleSurface::AgentThread(_)) - && self.has_open_project(cx) - && !self.is_title_editor_focused(window, cx), - |this| { - this.child(gradient_overlay).child( - h_flex() - .visible_on_hover("title_editor") - .absolute() - .right_0() - .h_full() - .bg(cx.theme().colors().tab_bar_background) - .child( - IconButton::new("edit_tile", IconName::Pencil) - .icon_size(IconSize::Small) - .tooltip(Tooltip::text("Edit Thread Title")), - ), - ) - }, - ) + .when(self.should_show_title_edit(window, cx), |this| { + this.child(gradient_overlay).child( + h_flex() + .visible_on_hover("title_editor") + .absolute() + .right_0() + .h_full() + .bg(cx.theme().colors().tab_bar_background) + .child( + IconButton::new("edit_tile", IconName::Pencil) + .icon_size(IconSize::Small) + .tooltip(Tooltip::text("Edit Thread Title")), + ), + ) + }) .into_any() } @@ -6824,6 +6827,42 @@ mod tests { }); } + #[gpui::test] + async fn test_title_edit_affordance_matches_threads_and_terminals(cx: &mut TestAppContext) { + let (panel, mut cx) = setup_panel(cx).await; + + panel.update_in(&mut cx, |panel, window, cx| { + panel.activate_draft(false, AgentThreadSource::AgentPanel, window, cx); + }); + cx.run_until_parked(); + + panel.update_in(&mut cx, |panel, window, cx| { + assert!(matches!( + panel.visible_surface(), + VisibleSurface::AgentThread(_) + )); + assert!(panel.should_show_title_edit(window, cx)); + }); + + let terminal_id = panel + .update_in(&mut cx, |panel, window, cx| { + panel.insert_test_terminal("Dev Server", true, window, cx) + }) + .expect("test terminal should be inserted"); + cx.run_until_parked(); + + panel.update_in(&mut cx, |panel, window, cx| { + assert!(matches!( + panel.visible_surface(), + VisibleSurface::Terminal(_) + )); + assert!(panel.should_show_title_edit(window, cx)); + + panel.edit_terminal_title(terminal_id, window, cx); + assert!(!panel.should_show_title_edit(window, cx)); + }); + } + #[gpui::test] async fn test_terminal_working_directory_uses_active_workspace_while_workspace_is_updating( cx: &mut TestAppContext,