From 2ac472e0e068770109c37917bf9d6368345a8325 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:31:36 -0500 Subject: [PATCH] Inline buttons --- crates/search2/src/buffer_search.rs | 32 ++++++++++++++++++----------- crates/search2/src/search.rs | 19 ----------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index dcf9c4c6f2220cddac91706f27b303d5cfb206da..ec70b3721996a9d8f483ebf7708019b7f94a1f91 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -289,18 +289,26 @@ impl Render for BufferSearchBar { .child(self.render_text_input(&self.replacement_editor, cx)), ) .when(should_show_replace_input, |this| { - this.child(super::render_replace_button( - ReplaceNext, - ui::Icon::ReplaceNext, - "Replace next", - cx.listener(|this, _, cx| this.replace_next(&ReplaceNext, cx)), - )) - .child(super::render_replace_button( - ReplaceAll, - ui::Icon::ReplaceAll, - "Replace all", - cx.listener(|this, _, cx| this.replace_all(&ReplaceAll, cx)), - )) + this.child( + IconButton::new("search-replace-next", ui::Icon::ReplaceNext) + .tooltip(move |cx| { + Tooltip::for_action("Replace next", &ReplaceNext, cx) + }) + .on_click(cx.listener(|this, _, cx| { + this.replace_next(&ReplaceNext, cx) + })), + ) + .child( + IconButton::new("search-replace-all", ui::Icon::ReplaceAll) + .tooltip(move |cx| { + Tooltip::for_action("Replace all", &ReplaceAll, cx) + }) + .on_click( + cx.listener(|this, _, cx| { + this.replace_all(&ReplaceAll, cx) + }), + ), + ) }) }), ) diff --git a/crates/search2/src/search.rs b/crates/search2/src/search.rs index 18fcc258f44497c8863f9000201238cebc1520ab..1d496a10b03e3ab6789d467d75d034f26a755134 100644 --- a/crates/search2/src/search.rs +++ b/crates/search2/src/search.rs @@ -5,10 +5,6 @@ pub use mode::SearchMode; use project::search::SearchQuery; use ui::{prelude::*, Tooltip}; use ui::{ButtonStyle, Icon, IconButton}; -//pub use project_search::{ProjectSearchBar, ProjectSearchView}; -// use theme::components::{ -// action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle, -// }; pub mod buffer_search; mod history; @@ -121,18 +117,3 @@ fn toggle_replace_button( .when(active, |button| button.style(ButtonStyle::Filled)) .tooltip(|cx| Tooltip::for_action("Toggle replace", &ToggleReplace, cx)) } - -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) - .tooltip({ - let action = action.boxed_clone(); - move |cx| Tooltip::for_action(tooltip, &*action, cx) - }) - .on_click(on_click) -}