Move Registrar implementation for Workspace to outer scope.

Piotr Osiewicz created

This fixes various actions like "Activate regex mode" that were dispatched onto main pane instead of assistant search bar.

Change summary

crates/search/src/buffer_search.rs | 38 ++++++++++++++++---------------
1 file changed, 20 insertions(+), 18 deletions(-)

Detailed changes

crates/search/src/buffer_search.rs 🔗

@@ -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 {