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.

settings_ui: Add `Clear` button to the search field (#56033)

Andrew Goodef5e87e5343d3
diff --git a/crates/settings_ui/src/settings_ui.rs b/crates/settings_ui/src/settings_ui.rs
index 223c39f2cdf..362dc2dd215 100644
--- a/crates/settings_ui/src/settings_ui.rs
+++ b/crates/settings_ui/src/settings_ui.rs
@@ -2022,6 +2022,14 @@ impl SettingsWindow {
this
}
+ fn clear_search(&mut self, window: &mut Window, cx: &mut Context<SettingsWindow>) {
+ if !self.search_bar.read(cx).is_empty(cx) {
+ self.search_bar.update(cx, |editor, cx| {
+ editor.set_text("", window, cx);
+ });
+ }
+ }
+
fn handle_project_event(
&mut self,
_: &Entity<Project>,
@@ -2979,7 +2987,12 @@ impl SettingsWindow {
// }
// }
- fn render_search(&self, window: &mut Window, cx: &mut App) -> impl IntoElement {
+ fn render_search(
+ &self,
+ window: &mut Window,
+ cx: &mut Context<SettingsWindow>,
+ ) -> Stateful<Div> {
+ let has_query = !self.search_bar.read(cx).is_empty(cx);
let (a11y_value, a11y_text_runs) =
text_field_a11y_state("settings-ui-search", &self.search_bar, window, cx);
@@ -2991,7 +3004,9 @@ impl SettingsWindow {
.track_focus(&self.search_bar.focus_handle(cx))
.a11y_synthetic_children(a11y_text_runs)
.py_1()
- .px_1p5()
+ .pl_1p5()
+ .pr_0p5()
+ .h_7()
.mb_3()
.gap_1p5()
.rounded_sm()
@@ -3000,6 +3015,17 @@ impl SettingsWindow {
.border_color(cx.theme().colors().border)
.child(Icon::new(IconName::MagnifyingGlass).color(Color::Muted))
.child(self.search_bar.clone())
+ .when(has_query, |this| {
+ this.child(
+ IconButton::new("clear-btn", IconName::Close)
+ .icon_color(Color::Muted)
+ .icon_size(IconSize::Small)
+ .tooltip(Tooltip::text("Clear"))
+ .on_click(cx.listener(|settings_window, _, window, cx| {
+ settings_window.clear_search(window, cx);
+ })),
+ )
+ })
}
fn render_nav(