mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 02:37:21 +00:00
Use Registrar in Assistant Panel.
This fixes various actions like "Activate regex mode" that were dispatched onto main pane instead of assistant search bar.
This commit is contained in:
parent
5ad125a9e9
commit
9cdcdbea41
2 changed files with 32 additions and 3 deletions
|
@ -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()
|
||||
|
|
|
@ -485,7 +485,6 @@ impl BufferSearchBar {
|
|||
cx.propagate();
|
||||
});
|
||||
registrar.register_handler(|this, deploy, cx| {
|
||||
dbg!("Deploying?");
|
||||
this.deploy(deploy, cx);
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue