Inline toggle replace button

This commit is contained in:
Marshall Bowers 2023-12-20 17:34:08 -05:00
parent 2ac472e0e0
commit e5e8e8882f
2 changed files with 15 additions and 17 deletions

View file

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

View file

@ -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))
}