From 53b608378c23fbdc2ba3baf79a180c1fe91aeb18 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:02:15 -0500 Subject: [PATCH 1/6] Don't apply the gap when we don't have any items in the first row --- crates/workspace2/src/toolbar.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/workspace2/src/toolbar.rs b/crates/workspace2/src/toolbar.rs index cd25582f36cbd397688a500e85c0e405865dae63..4431e1b3ff39d7e595611cfb230dcb6a770f1d05 100644 --- a/crates/workspace2/src/toolbar.rs +++ b/crates/workspace2/src/toolbar.rs @@ -102,16 +102,19 @@ impl Render for Toolbar { let secondary_item = self.secondary_items().next().map(|item| item.to_any()); + let has_left_items = self.left_items().count() > 0; + let has_right_items = self.right_items().count() > 0; + v_stack() .p_1() - .gap_2() + .when(has_left_items || has_right_items, |this| this.gap_2()) .border_b() .border_color(cx.theme().colors().border_variant) .bg(cx.theme().colors().toolbar_background) .child( h_stack() .justify_between() - .when(self.left_items().count() > 0, |this| { + .when(has_left_items, |this| { this.child( h_stack() .flex_1() @@ -119,7 +122,7 @@ impl Render for Toolbar { .children(self.left_items().map(|item| item.to_any())), ) }) - .when(self.right_items().count() > 0, |this| { + .when(has_right_items, |this| { this.child( h_stack() .flex_1() From b9bc74abe55915a8e05308b07e3dcf27a244fc07 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:03:44 -0500 Subject: [PATCH 2/6] Increase toolbar padding --- crates/workspace2/src/toolbar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/workspace2/src/toolbar.rs b/crates/workspace2/src/toolbar.rs index 4431e1b3ff39d7e595611cfb230dcb6a770f1d05..f8bca157c37275a617c30bb68b15346767a3f974 100644 --- a/crates/workspace2/src/toolbar.rs +++ b/crates/workspace2/src/toolbar.rs @@ -106,7 +106,7 @@ impl Render for Toolbar { let has_right_items = self.right_items().count() > 0; v_stack() - .p_1() + .p_2() .when(has_left_items || has_right_items, |this| this.gap_2()) .border_b() .border_color(cx.theme().colors().border_variant) From b493d8f6c0b84e90af061eabe0b825072b18b0b6 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:10:27 -0500 Subject: [PATCH 3/6] Improve spacing of items in buffer search bar --- crates/search2/src/buffer_search.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index ebaf111e6061c9b9ca032774c9fd1c85f31b552f..51557320f78b6c95c2d321706970068a555206f2 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -214,6 +214,8 @@ impl Render for BufferSearchBar { } h_stack() + .w_full() + .gap_2() .key_context(key_context) .on_action(cx.listener(Self::previous_history_query)) .on_action(cx.listener(Self::next_history_query)) @@ -239,7 +241,6 @@ impl Render for BufferSearchBar { .when(self.supported_options().word, |this| { this.on_action(cx.listener(Self::toggle_whole_word)) }) - .w_full() .child( h_stack() .flex_1() @@ -268,6 +269,7 @@ impl Render for BufferSearchBar { ) .child( h_stack() + .gap_2() .flex_none() .child( h_stack() From 8a8b498ee114cded149172515dc1e2e13f2bfed2 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:25:38 -0500 Subject: [PATCH 4/6] Style replace input --- crates/search2/src/buffer_search.rs | 61 +++++++++++++++++------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 51557320f78b6c95c2d321706970068a555206f2..dcf9c4c6f2220cddac91706f27b303d5cfb206da 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -189,22 +189,6 @@ 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", - 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", - cx.listener(|this, _, cx| this.replace_next(&ReplaceNext, cx)), - ) - }); let in_replace = self.replacement_editor.focus_handle(cx).is_focused(cx); let mut key_context = KeyContext::default(); @@ -290,16 +274,47 @@ impl Render for BufferSearchBar { .gap_0p5() .flex_1() .when(self.replace_enabled, |this| { - this.child(self.replacement_editor.clone()) - .children(replace_next) - .children(replace_all) + this.child( + h_stack() + .flex_1() + // We're giving this a fixed height to match the height of the search input, + // which has an icon inside that is increasing its height. + .h_8() + .px_2() + .py_1() + .gap_2() + .border_1() + .border_color(cx.theme().colors().border) + .rounded_lg() + .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)), + )) + }) }), ) .child( h_stack() .gap_0p5() .flex_none() - .child(self.render_action_button()) + .child( + IconButton::new("select-all", ui::Icon::SelectAll) + .on_click(|_, cx| cx.dispatch_action(SelectAllMatches.boxed_clone())) + .tooltip(|cx| { + Tooltip::for_action("Select all matches", &SelectAllMatches, cx) + }), + ) .children(match_count) .child(render_nav_button( ui::Icon::ChevronLeft, @@ -627,12 +642,6 @@ impl BufferSearchBar { self.update_matches(cx) } - fn render_action_button(&self) -> impl IntoElement { - IconButton::new("select-all", ui::Icon::SelectAll) - .on_click(|_, cx| cx.dispatch_action(SelectAllMatches.boxed_clone())) - .tooltip(|cx| Tooltip::for_action("Select all matches", &SelectAllMatches, cx)) - } - fn render_search_option_button( &self, option: SearchOptions, From 2ac472e0e068770109c37917bf9d6368345a8325 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:31:36 -0500 Subject: [PATCH 5/6] 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) -} From e5e8e8882f162a125bfa15acaf41c10162fc1c21 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Dec 2023 17:34:08 -0500 Subject: [PATCH 6/6] 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)) -}