Inline toggle replace button

Marshall Bowers created

Change summary

crates/search2/src/buffer_search.rs | 18 ++++++++++++++----
crates/search2/src/search.rs        | 14 +-------------
2 files changed, 15 insertions(+), 17 deletions(-)

Detailed changes

crates/search2/src/buffer_search.rs 🔗

@@ -261,12 +261,22 @@ impl Render for BufferSearchBar {
                             .child(search_button_for_mode(SearchMode::Regex)),
                     )
                     .when(supported_options.replacement, |this| {
-                        this.child(super::toggle_replace_button(
-                            self.replace_enabled,
-                            cx.listener(|this, _: &ClickEvent, cx| {
+                        this.child(
+                            IconButton::new(
+                                "buffer-search-bar-toggle-replace-button",
+                                Icon::Replace,
+                            )
+                            .style(ButtonStyle::Subtle)
+                            .when(self.replace_enabled, |button| {
+                                button.style(ButtonStyle::Filled)
+                            })
+                            .on_click(cx.listener(|this, _: &ClickEvent, cx| {
                                 this.toggle_replace(&ToggleReplace, cx);
+                            }))
+                            .tooltip(|cx| {
+                                Tooltip::for_action("Toggle replace", &ToggleReplace, cx)
                             }),
-                        ))
+                        )
                     }),
             )
             .child(

crates/search2/src/search.rs 🔗

@@ -4,7 +4,7 @@ use gpui::{actions, Action, AppContext, IntoElement};
 pub use mode::SearchMode;
 use project::search::SearchQuery;
 use ui::{prelude::*, Tooltip};
-use ui::{ButtonStyle, Icon, IconButton};
+use ui::{ButtonStyle, IconButton};
 
 pub mod buffer_search;
 mod history;
@@ -105,15 +105,3 @@ impl SearchOptions {
             })
     }
 }
-
-fn toggle_replace_button(
-    active: bool,
-    action: impl Fn(&gpui::ClickEvent, &mut WindowContext) + 'static,
-) -> impl IntoElement {
-    // todo: add toggle_replace button
-    IconButton::new("buffer-search-bar-toggle-replace-button", Icon::Replace)
-        .on_click(action)
-        .style(ButtonStyle::Subtle)
-        .when(active, |button| button.style(ButtonStyle::Filled))
-        .tooltip(|cx| Tooltip::for_action("Toggle replace", &ToggleReplace, cx))
-}