Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Inline toggle replace button

Marshall Bowerse5e8e8882f16
diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs
index ec70b372199..06e1b625bc4 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 1d496a10b03..a5bd299e874 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))
-}