From d02b071002acbce824810a20ec1ed4a635ca5207 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 21:04:25 -0500 Subject: [PATCH] FindBar: a plain integrated field (no clear button) and a sliders options icon; TextField::clear_button (trial) --- crates/text/src/ui/find/bar.rs | 3 ++- crates/text/tests/it/find_bar.rs | 14 ++++++++++++++ crates/ui-widgets/src/text/text_field.rs | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/text/src/ui/find/bar.rs b/crates/text/src/ui/find/bar.rs index ce4e18f7c..e93fecd82 100644 --- a/crates/text/src/ui/find/bar.rs +++ b/crates/text/src/ui/find/bar.rs @@ -178,6 +178,7 @@ impl<'a> FindBar<'a> { } Row::new().show(ui, |ui, _| { let edit = TextField::search(words.find_text.clone(), Bind::given(query.clone())) + .clear_button(false) .placeholder(words.find_text.clone()) .select_all(to_query) .show(ui); @@ -216,7 +217,7 @@ impl<'a> FindBar<'a> { *open = !*open; } let active = options.match_case || options.whole_word; - let button = IconButton::new(IconId::new("settings")).label(words.options.clone()).popup(PopupKind::Menu).selected(active).show(ui); + let button = IconButton::new(IconId::new("sliders-horizontal")).label(words.options.clone()).popup(PopupKind::Menu).selected(active).show(ui); let entries = [ Entry::new(BarOption::WholeWords, words.whole_words_only.clone()).checked(options.whole_word), Entry::new(BarOption::MatchCase, words.case_sensitive.clone()).checked(options.match_case), diff --git a/crates/text/tests/it/find_bar.rs b/crates/text/tests/it/find_bar.rs index e7669c237..262d9b635 100644 --- a/crates/text/tests/it/find_bar.rs +++ b/crates/text/tests/it/find_bar.rs @@ -118,3 +118,17 @@ fn asking_for_the_bar_again_selects_its_query_unless_a_composition_runs() { bar.fixture.type_text("dog").settle(); assert_eq!(bar.query(), "dog", "after the commit the next request selects the query again"); } + +// Production's find field is a plain integrated one: no clear button beside the text, and Escape still clears it. +#[trial] +fn the_find_field_has_no_clear_button_and_escape_clears_it() { + let mut bar = Bar::new(); + bar.ask(); + bar.fixture.type_text("cat"); + bar.fixture.frame(Vec::new()).settle(); + assert_eq!(bar.query(), "cat"); + assert!(bar.fixture.by_label("Clear").is_none(), "no clear button beside the text"); + bar.fixture.key(Key::Escape, Modifiers::NONE); + bar.fixture.frame(Vec::new()).settle(); + assert_eq!(bar.query(), "", "Escape clears the query"); +} diff --git a/crates/ui-widgets/src/text/text_field.rs b/crates/ui-widgets/src/text/text_field.rs index e8cda5c7f..a372209fd 100644 --- a/crates/ui-widgets/src/text/text_field.rs +++ b/crates/ui-widgets/src/text/text_field.rs @@ -62,6 +62,8 @@ pub struct TextField<'a, C: Codec + Clone + 'static = PlainText> { pub(super) empty: Option, /// The search form: a clear part while there is text, and Escape clears the text. search: bool, + /// Whether the search form shows its clear button (on); Escape still clears the text without it. + clear_button: bool, /// The adornments before the text, in reading order. leading: Vec, /// The field reserves and paints a chevron at the end, for the host's popup. @@ -103,6 +105,7 @@ impl<'a, C: Codec + Clone + 'static> TextField<'a, C> { limit: Limit::Default, empty: None, search: false, + clear_button: true, leading: Vec::new(), arrow: false, drives: None, @@ -110,6 +113,14 @@ impl<'a, C: Codec + Clone + 'static> TextField<'a, C> { .label(label) } + /// Whether a search field shows its clear button while there is text. Off, the field is a plain integrated one + /// (a find bar's): Escape still clears it. + #[must_use] + pub fn clear_button(mut self, on: bool) -> Self { + self.clear_button = on; + self + } + /// Shown while the text is empty. #[must_use] pub fn placeholder(mut self, placeholder: impl Into