From e5e8e8882f162a125bfa15acaf41c10162fc1c21 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:34:08 -0500 Subject: [PATCH] Inline toggle replace button --- crates/search2/src/buffer_search.rs | 18 ++++++++++++++---- crates/search2/src/search.rs | 14 +------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index ec70b3721996a9d8f483ebf7708019b7f94a1f91..06e1b625bc4baaa79264467ac10c1a0a23465e63 100644 --- a/crates/search2/src/buffer_search.rs +++ b/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( diff --git a/crates/search2/src/search.rs b/crates/search2/src/search.rs index 1d496a10b03e3ab6789d467d75d034f26a755134..a5bd299e874603a9c2be6147f0c5e5a9d74ad8d9 100644 --- a/crates/search2/src/search.rs +++ b/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)) -}