Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent_ui: Open a stopped subagent card's part in full screen (#66252)

Ben Brandt7de7bfdba202
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs
index 390a7d42269..6c412967821 100644
--- a/crates/agent_ui/src/conversation_view.rs
+++ b/crates/agent_ui/src/conversation_view.rs
@@ -20647,11 +20647,14 @@ pub(crate) mod tests {
.expect("reported state");
};
let running = || acp_v2::StateUpdate::Running(acp_v2::RunningStateUpdate::new());
+ // Long enough that the subagent's view overflows, so its scroll position shows.
+ let long_text = vec!["Working"; 40].join("\n\n");
let work = |message_id: &str, cx: &mut VisualTestContext| {
child
.update(cx, |child, cx| {
child.upsert_assistant_message(
- acp_v2::AgentMessage::new(message_id).content(vec!["Working".into()]),
+ acp_v2::AgentMessage::new(message_id)
+ .content(vec![long_text.as_str().into()]),
cx,
)
})
@@ -20728,6 +20731,53 @@ pub(crate) mod tests {
&& cx.debug_bounds("session-message-participant-3").is_some(),
"the unlinked message is drawn as a row"
);
+
+ let parent_view = active_thread(&conversation_view, cx);
+ let child_view = conversation_view
+ .read_with(cx, |view, _| view.thread_view(&child_session_id))
+ .expect("subagent view");
+ let child_scroll_top = |cx: &mut VisualTestContext| {
+ child_view.read_with(cx, |view, _| view.list_state.logical_scroll_top())
+ };
+ let open_fullscreen = |message_id: &str,
+ selector: &'static str,
+ cx: &mut VisualTestContext| {
+ conversation_view.update_in(cx, |view, window, cx| {
+ view.navigate_to_thread(root_session_id.clone(), window, cx)
+ });
+ parent_view.update(cx, |view, cx| {
+ view.entry_view_state.update(cx, |state, _| {
+ if !state.is_session_message_card_expanded(&acp_v2::MessageId::new(message_id))
+ {
+ state.toggle_session_message_card_expansion(&acp_v2::MessageId::new(
+ message_id,
+ ));
+ }
+ });
+ cx.notify();
+ });
+ cx.run_until_parked();
+ let toggle = cx.debug_bounds(selector).expect("full screen button");
+ cx.simulate_click(toggle.center(), gpui::Modifiers::default());
+ cx.run_until_parked();
+ assert_eq!(active_thread(&conversation_view, cx), child_view);
+ };
+
+ child_view.update(cx, |view, cx| view.scroll_to_entry(4, cx));
+ open_fullscreen("follow-up", "subagent-fullscreen-1", cx);
+ assert_eq!(
+ child_scroll_top(cx).item_ix,
+ 2,
+ "a stopped card opens at the start of its part"
+ );
+
+ child_view.update(cx, |view, cx| view.scroll_to_entry(3, cx));
+ open_fullscreen("retry", "subagent-fullscreen-2", cx);
+ assert_eq!(
+ child_scroll_top(cx).item_ix,
+ 3,
+ "a running card leaves the subagent where it was"
+ );
}
#[gpui::test]
diff --git a/crates/agent_ui/src/conversation_view/subagent_card.rs b/crates/agent_ui/src/conversation_view/subagent_card.rs
index c4e511abe74..e185d41191f 100644
--- a/crates/agent_ui/src/conversation_view/subagent_card.rs
+++ b/crates/agent_ui/src/conversation_view/subagent_card.rs
@@ -259,6 +259,14 @@ impl SubagentCardState {
})
}
+ /// The subagent entry that full screen should open at: the start of this card's part
+ /// once its work has stopped, or `None` while it runs, so the subagent's view keeps
+ /// following its latest entries.
+ pub(crate) fn fullscreen_entry(&self) -> Option<usize> {
+ (self.status != SubagentStatus::Running)
+ .then(|| self.entries.map_or(0, |entries| entries.start))
+ }
+
/// The last `max_entries` of the entries this card covers.
pub(crate) fn preview_range(&self, total_entries: usize, max_entries: usize) -> Range<usize> {
let mut range = match self.entries {
@@ -424,6 +432,27 @@ mod tests {
}
}
+ #[test]
+ fn fullscreen_opens_a_stopped_card_at_the_start_of_its_part() {
+ let part = Some(SubagentEntries {
+ start: 4,
+ end: Some(6),
+ });
+ assert_eq!(
+ card(None, SubagentStatus::Running, part).fullscreen_entry(),
+ None
+ );
+ for status in [
+ SubagentStatus::Completed,
+ SubagentStatus::Canceled,
+ SubagentStatus::Failed,
+ SubagentStatus::Unknown,
+ ] {
+ assert_eq!(card(None, status, part).fullscreen_entry(), Some(4));
+ assert_eq!(card(None, status, None).fullscreen_entry(), Some(0));
+ }
+ }
+
#[test]
fn preview_range_shows_the_last_entries_the_card_covers() {
let whole_thread = card(None, SubagentStatus::Running, None);
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index 34032b1bd50..4a3871c754c 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -12245,9 +12245,12 @@ impl ThreadView {
.pending_tool_call(tv_session_id, cx);
let nav_session_id = tv_session_id.clone();
+ let fullscreen_entry = state.fullscreen_entry();
+ let subagent_view = thread_view.clone();
let fullscreen_toggle = h_flex()
.id(entry_ix)
+ .debug_selector(move || format!("subagent-fullscreen-{entry_ix}"))
.py_1()
.w_full()
.justify_center()
@@ -12269,6 +12272,9 @@ impl ThreadView {
this.navigate_to_thread(nav_session_id.clone(), window, cx);
})
.ok();
+ if let Some(entry_ix) = fullscreen_entry {
+ subagent_view.update(cx, |view, cx| view.scroll_to_entry(entry_ix, cx));
+ }
}));
if is_running && let Some((_, subagent_tool_call_id, _)) = pending_tool_call {