diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 9221d87f60..7ab6aba227 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -38,7 +38,7 @@ use gpui::{ }; use language::{language_settings::SoftWrap, Buffer, LanguageRegistry, ToOffset as _}; use project::Project; -use search::BufferSearchBar; +use search::{buffer_search::SearchActionsRegistrar, BufferSearchBar}; use semantic_index::{SemanticIndex, SemanticIndexStatus}; use settings::{Settings, SettingsStore}; use std::{ @@ -1100,6 +1100,26 @@ fn build_api_key_editor(cx: &mut ViewContext) -> View { }) } +struct SearchRegistrar<'a, 'b> { + div: Option
, + cx: &'a mut ViewContext<'b, AssistantPanel>, +} + +impl SearchActionsRegistrar for SearchRegistrar<'_, '_> { + fn register_handler( + &mut self, + callback: fn(&mut BufferSearchBar, &A, &mut ViewContext), + ) { + self.div = self.div.take().map(|div| { + div.on_action(self.cx.listener(move |this, action, cx| { + this.toolbar + .read(cx) + .item_of_type::() + .map(|search_bar| search_bar.update(cx, |this, cx| callback(this, action, cx))); + })) + }); + } +} impl Render for AssistantPanel { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { if let Some(api_key_editor) = self.api_key_editor.clone() { @@ -1156,6 +1176,16 @@ impl Render for AssistantPanel { div() }); + let contents = if self.active_editor().is_some() { + let mut registrar = SearchRegistrar { + div: Some(div()), + cx, + }; + BufferSearchBar::register_inner(&mut registrar); + registrar.div.unwrap() + } else { + div() + }; v_stack() .key_context("AssistantPanel") .size_full() @@ -1176,7 +1206,7 @@ impl Render for AssistantPanel { Some(self.toolbar.clone()) }) .child( - div() + contents .flex_1() .child(if let Some(editor) = self.active_editor() { editor.clone().into_any_element() diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index afd0f6c615..6e44db60c5 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -485,7 +485,6 @@ impl BufferSearchBar { cx.propagate(); }); registrar.register_handler(|this, deploy, cx| { - dbg!("Deploying?"); this.deploy(deploy, cx); }) }