Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use Registrar in Assistant Panel.
Piotr Osiewicz9cdcdbea419e
diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rsindex 9221d87f60f..7ab6aba227d 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<AssistantPanel>) -> View<Editor> {})}+struct SearchRegistrar<'a, 'b> {+ div: Option<Div>,+ cx: &'a mut ViewContext<'b, AssistantPanel>,+}++impl SearchActionsRegistrar for SearchRegistrar<'_, '_> {+ fn register_handler<A: Action>(+ &mut self,+ callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),+ ) {+ self.div = self.div.take().map(|div| {+ div.on_action(self.cx.listener(move |this, action, cx| {+ this.toolbar+ .read(cx)+ .item_of_type::<BufferSearchBar>()+ .map(|search_bar| search_bar.update(cx, |this, cx| callback(this, action, cx)));+ }))+ });+ }+}impl Render for AssistantPanel {fn render(&mut self, cx: &mut ViewContext<Self>) -> 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.rsindex afd0f6c6156..6e44db60c54 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);})}