From 13f9fec0bd916bb1dfd79c87520b7ee124536ff7 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:38:58 +0100 Subject: [PATCH] fixup! Move away from using cx.dispatch_action in buffer search --- crates/search2/src/buffer_search.rs | 17 ++++++++++++++--- crates/search2/src/search.rs | 5 ++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 481bc757ebdc0f..2598049ce6c4f5 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -154,10 +154,21 @@ impl Render for BufferSearchBar { Some(ui::Label::new(message)) }); let should_show_replace_input = self.replace_enabled && supported_options.replacement; - let replace_all = should_show_replace_input - .then(|| super::render_replace_button(ReplaceAll, ui::Icon::ReplaceAll, "Replace all")); + let replace_all = should_show_replace_input.then(|| { + super::render_replace_button( + ReplaceAll, + ui::Icon::ReplaceAll, + "Replace all", + cx.listener(|this, _, cx| this.replace_all(&ReplaceAll, cx)), + ) + }); let replace_next = should_show_replace_input.then(|| { - super::render_replace_button(ReplaceNext, ui::Icon::ReplaceNext, "Replace next") + super::render_replace_button( + ReplaceNext, + ui::Icon::ReplaceNext, + "Replace next", + cx.listener(|this, _, cx| this.replace_next(&ReplaceNext, cx)), + ) }); let in_replace = self.replacement_editor.focus_handle(cx).is_focused(cx); diff --git a/crates/search2/src/search.rs b/crates/search2/src/search.rs index 41be2508b3096d..015c126aa1ef5a 100644 --- a/crates/search2/src/search.rs +++ b/crates/search2/src/search.rs @@ -121,6 +121,7 @@ fn render_replace_button( action: impl Action + 'static + Send + Sync, icon: Icon, tooltip: &'static str, + on_click: impl Fn(&gpui::ClickEvent, &mut WindowContext) + 'static, ) -> impl IntoElement { let id: SharedString = format!("search-replace-{}", action.name()).into(); IconButton::new(id, icon) @@ -128,7 +129,5 @@ fn render_replace_button( let action = action.boxed_clone(); move |cx| Tooltip::for_action(tooltip, &*action, cx) }) - .on_click(move |_, cx| { - cx.dispatch_action(action.boxed_clone()); - }) + .on_click(on_click) }