agent_ui: Show title edit for terminals in agent panel (#57005)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
This commit is contained in:
Ben Brandt 2026-05-17 19:01:36 +02:00 committed by GitHub
parent f7ca86e6ee
commit ce38fd67a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3953,6 +3953,14 @@ impl AgentPanel {
}
}
fn should_show_title_edit(&self, window: &Window, cx: &Context<Self>) -> 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<Self>) -> 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,