Move Registrar implementation for Workspace to outer scope.

This fixes various actions like "Activate regex mode" that were dispatched onto main pane instead of assistant search bar.
This commit is contained in:
Piotr Osiewicz 2024-01-04 17:04:28 +01:00
parent b6655def70
commit 783256c80e

View File

@ -470,6 +470,26 @@ impl<T: 'static> SearchActionsRegistrar for DivRegistrar<'_, '_, T> {
});
}
}
/// Register actions for an active pane.
impl SearchActionsRegistrar for Workspace {
fn register_handler<A: Action>(
&mut self,
callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
) {
self.register_action(move |workspace, action: &A, cx| {
let pane = workspace.active_pane();
pane.update(cx, move |this, cx| {
this.toolbar().update(cx, move |this, cx| {
if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
search_bar.update(cx, move |this, cx| callback(this, action, cx));
cx.notify();
}
})
});
});
}
}
impl BufferSearchBar {
pub fn register_inner(registrar: &mut impl SearchActionsRegistrar) {
registrar.register_handler(|this, action: &ToggleCaseSensitive, cx| {
@ -529,24 +549,6 @@ impl BufferSearchBar {
})
}
fn register(workspace: &mut Workspace) {
impl SearchActionsRegistrar for Workspace {
fn register_handler<A: Action>(
&mut self,
callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
) {
self.register_action(move |workspace, action: &A, cx| {
let pane = workspace.active_pane();
pane.update(cx, move |this, cx| {
this.toolbar().update(cx, move |this, cx| {
if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
search_bar.update(cx, move |this, cx| callback(this, action, cx));
cx.notify();
}
})
});
});
}
}
Self::register_inner(workspace);
}
pub fn new(cx: &mut ViewContext<Self>) -> Self {