diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs index 86f920c157a7ea0a5895f03342df73e0403b473f..1a2f5d38af2d13cf7efc4829d498fa88dc4a09cd 100644 --- a/crates/agent_ui/src/conversation_view/thread_view.rs +++ b/crates/agent_ui/src/conversation_view/thread_view.rs @@ -4760,8 +4760,8 @@ impl ThreadView { .into_any() } } - AgentThreadEntry::ToolCall(tool_call) => self - .render_any_tool_call( + AgentThreadEntry::ToolCall(tool_call) => { + let tool_call = self.render_any_tool_call( self.thread.read(cx).session_id(), entry_ix, tool_call, @@ -4769,8 +4769,19 @@ impl ThreadView { false, window, cx, - ) - .into_any(), + ); + + if let Some(handle) = self + .entry_view_state + .read(cx) + .entry(entry_ix) + .and_then(|entry| entry.focus_handle(cx)) + { + tool_call.track_focus(&handle).into_any() + } else { + tool_call.into_any() + } + } AgentThreadEntry::CompletedPlan(entries) => { self.render_completed_plan(entries, window, cx) } diff --git a/crates/agent_ui/src/entry_view_state.rs b/crates/agent_ui/src/entry_view_state.rs index 071b92eb3ae6b68548539e58b16949d7c72bab80..415cd1f3db19df29895d7dd984e7ac4fb4a7b47b 100644 --- a/crates/agent_ui/src/entry_view_state.rs +++ b/crates/agent_ui/src/entry_view_state.rs @@ -130,6 +130,7 @@ impl EntryViewState { index, Entry::ToolCall(ToolCallEntry { content: HashMap::default(), + focus_handle: cx.focus_handle(), }), ); let Some(Entry::ToolCall(tool_call)) = self.entries.get_mut(index) else { @@ -262,7 +263,7 @@ impl EntryViewState { Entry::UserMessage { .. } | Entry::AssistantMessage { .. } | Entry::CompletedPlan => {} - Entry::ToolCall(ToolCallEntry { content }) => { + Entry::ToolCall(ToolCallEntry { content, .. }) => { for view in content.values() { if let Ok(diff_editor) = view.clone().downcast::() { diff_editor.update(cx, |diff_editor, cx| { @@ -321,6 +322,7 @@ impl AssistantMessageEntry { #[derive(Debug)] pub struct ToolCallEntry { content: HashMap, + focus_handle: FocusHandle, } #[derive(Debug)] @@ -336,7 +338,8 @@ impl Entry { match self { Self::UserMessage(editor) => Some(editor.read(cx).focus_handle(cx)), Self::AssistantMessage(message) => Some(message.focus_handle.clone()), - Self::ToolCall(_) | Self::CompletedPlan => None, + Self::ToolCall(tool_call) => Some(tool_call.focus_handle.clone()), + Self::CompletedPlan => None, } } @@ -376,7 +379,7 @@ impl Entry { fn content_map(&self) -> Option<&HashMap> { match self { - Self::ToolCall(ToolCallEntry { content }) => Some(content), + Self::ToolCall(ToolCallEntry { content, .. }) => Some(content), _ => None, } } @@ -384,12 +387,29 @@ impl Entry { #[cfg(test)] pub fn has_content(&self) -> bool { match self { - Self::ToolCall(ToolCallEntry { content }) => !content.is_empty(), + Self::ToolCall(ToolCallEntry { content, .. }) => !content.is_empty(), Self::UserMessage(_) | Self::AssistantMessage(_) | Self::CompletedPlan => false, } } } +impl Focusable for ToolCallEntry { + fn focus_handle(&self, _cx: &App) -> FocusHandle { + self.focus_handle.clone() + } +} + +impl Focusable for Entry { + fn focus_handle(&self, cx: &App) -> FocusHandle { + match self { + Self::UserMessage(editor) => editor.read(cx).focus_handle(cx), + Self::AssistantMessage(message) => message.focus_handle.clone(), + Self::ToolCall(tool_call) => tool_call.focus_handle.clone(), + Self::CompletedPlan => cx.focus_handle(), + } + } +} + fn create_terminal( workspace: WeakEntity, project: WeakEntity,