From 71641245123d52a7f310eb6b1283a1d1b5bb5daa Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Mon, 5 May 2025 10:26:43 -0600 Subject: [PATCH] agent panel: Bring back search within text threads (#29934) Release Notes: - N/A --- Cargo.lock | 1 + crates/agent/Cargo.toml | 3 +- crates/agent/src/assistant_panel.rs | 64 ++++++++++++++++++++++++++--- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9bdd26080b0e93f08362ba26b449570d9441b06..4984de3fbbb95021b67be0f9112af9f5ec7102af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,6 +106,7 @@ dependencies = [ "rope", "rules_library", "schemars", + "search", "serde", "serde_json", "serde_json_lenient", diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.toml index 36c4f3f0421c90b45a6e152cc7b7e3346a84d797..6ffa5880a3e05a1cd20589acc7751e48740e4d5d 100644 --- a/crates/agent/Cargo.toml +++ b/crates/agent/Cargo.toml @@ -64,13 +64,14 @@ paths.workspace = true picker.workspace = true postage.workspace = true project.workspace = true -rules_library.workspace = true prompt_store.workspace = true proto.workspace = true ref-cast.workspace = true release_channel.workspace = true rope.workspace = true +rules_library.workspace = true schemars.workspace = true +search.workspace = true serde.workspace = true serde_json.workspace = true serde_json_lenient.workspace = true diff --git a/crates/agent/src/assistant_panel.rs b/crates/agent/src/assistant_panel.rs index 4596005b29fde2b2b68398f39962b971ddb0dd39..64484b14344031cb07d590f263e3ef828926f359 100644 --- a/crates/agent/src/assistant_panel.rs +++ b/crates/agent/src/assistant_panel.rs @@ -31,6 +31,7 @@ use project::Project; use prompt_store::{PromptBuilder, PromptStore, UserPromptId}; use proto::Plan; use rules_library::{RulesLibrary, open_rules_library}; +use search::{BufferSearchBar, buffer_search::DivRegistrar}; use settings::{Settings, update_settings_file}; use time::UtcOffset; use ui::{ @@ -39,7 +40,7 @@ use ui::{ }; use util::ResultExt as _; use workspace::dock::{DockPosition, Panel, PanelEvent}; -use workspace::{CollaboratorId, Workspace}; +use workspace::{CollaboratorId, ToolbarItemView, Workspace}; use zed_actions::agent::OpenConfiguration; use zed_actions::assistant::{OpenRulesLibrary, ToggleFocus}; use zed_llm_client::UsageLimit; @@ -151,6 +152,7 @@ enum ActiveView { PromptEditor { context_editor: Entity, title_editor: Entity, + buffer_search_bar: Entity, _subscriptions: Vec, }, History, @@ -216,6 +218,7 @@ impl ActiveView { pub fn prompt_editor( context_editor: Entity, + language_registry: Arc, window: &mut Window, cx: &mut App, ) -> Self { @@ -284,9 +287,16 @@ impl ActiveView { }), ]; + let buffer_search_bar = + cx.new(|cx| BufferSearchBar::new(Some(language_registry), window, cx)); + buffer_search_bar.update(cx, |buffer_search_bar, cx| { + buffer_search_bar.set_active_pane_item(Some(&context_editor), window, cx) + }); + Self::PromptEditor { context_editor, title_editor: editor, + buffer_search_bar, _subscriptions: subscriptions, } } @@ -785,7 +795,12 @@ impl AssistantPanel { }); self.set_active_view( - ActiveView::prompt_editor(context_editor.clone(), window, cx), + ActiveView::prompt_editor( + context_editor.clone(), + self.language_registry.clone(), + window, + cx, + ), window, cx, ); @@ -861,7 +876,12 @@ impl AssistantPanel { }); this.set_active_view( - ActiveView::prompt_editor(editor.clone(), window, cx), + ActiveView::prompt_editor( + editor.clone(), + this.language_registry.clone(), + window, + cx, + ), window, cx, ); @@ -2314,8 +2334,42 @@ impl Render for AssistantPanel { .child(h_flex().child(self.message_editor.clone())) .children(self.render_last_error(cx)), ActiveView::History => parent.child(self.history.clone()), - ActiveView::PromptEditor { context_editor, .. } => { - parent.child(context_editor.clone()) + ActiveView::PromptEditor { + context_editor, + buffer_search_bar, + .. + } => { + let mut registrar = DivRegistrar::new( + |this, _, _cx| match &this.active_view { + ActiveView::PromptEditor { + buffer_search_bar, .. + } => Some(buffer_search_bar.clone()), + _ => None, + }, + cx, + ); + BufferSearchBar::register(&mut registrar); + parent.child( + registrar + .into_div() + .size_full() + .map(|parent| { + buffer_search_bar.update(cx, |buffer_search_bar, cx| { + if buffer_search_bar.is_dismissed() { + return parent; + } + parent.child( + div() + .p(DynamicSpacing::Base08.rems(cx)) + .border_b_1() + .border_color(cx.theme().colors().border_variant) + .bg(cx.theme().colors().editor_background) + .child(buffer_search_bar.render(window, cx)), + ) + }) + }) + .child(context_editor.clone()), + ) } ActiveView::Configuration => parent.children(self.configuration.clone()), })