From 4854e2cff65021e9319cb30d79de71e2b588ca20 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 23 Nov 2026 07:43:54 -0500 Subject: [PATCH] fw sync: a search field's Clear shows the empty text in the pass of its click Upstream 819753137 answers injected input with the pass that ran it. The clear part empties the value in update, after the text part showed the old text, so the reply's tree still read it. The click now reruns the pass (discard_pass), and the rerun's tree reads empty. Trial: text::text_field::the_clear_part_empties_the_field_in_the_pass_of_its_click. --- crates/ui-widgets/src/text/text_field.rs | 3 +++ crates/ui-widgets/tests/it/text/text_field.rs | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/crates/ui-widgets/src/text/text_field.rs b/crates/ui-widgets/src/text/text_field.rs index 8ff669904..729528ab7 100644 --- a/crates/ui-widgets/src/text/text_field.rs +++ b/crates/ui-widgets/src/text/text_field.rs @@ -438,6 +438,9 @@ impl Component for TextField<'_, C> { && let Some(empty) = self.empty.clone() { cx.set(empty); + // The text part showed the old text earlier in this pass: the pass runs again, so the field shows and reports + // the empty text in the pass that took the click, not one pass later. + crate::runtime::frame::discard_pass(&cx.core.ctx, "a search field's clear part emptied it"); } } diff --git a/crates/ui-widgets/tests/it/text/text_field.rs b/crates/ui-widgets/tests/it/text/text_field.rs index dbff89867..06588fb22 100644 --- a/crates/ui-widgets/tests/it/text/text_field.rs +++ b/crates/ui-widgets/tests/it/text/text_field.rs @@ -275,3 +275,25 @@ fn a_bound_caret_moves_the_caret_and_follows_it() { fixture.idle(2); assert_eq!(caret.get(), 4, "the user's caret move past the two-byte \"é\" writes its byte offset back"); } + +/// The clear part empties the field in the pass that takes its click: the field's node reads empty after that one pass, +/// as an agent's click reply comes with it (the control channel answers with the pass that ran the input). +#[trial] +fn the_clear_part_empties_the_field_in_the_pass_of_its_click() { + use craft_ui::testing::focus::AccessActionKind; + let id = Rc::new(Cell::new(Id::NULL)); + let field = id.clone(); + // The app's own text, as a search panel's query is. + let text = Rc::new(RefCell::new(String::from("abc"))); + let held = text.clone(); + let mut fixture = Fixture::new(move |ui| { + let mut query = held.borrow_mut(); + field.set(TextField::search("Search", Bind::bound(&mut *query)).show(ui).response.id); + }); + fixture.settle(); + assert_eq!(fixture.tree().value(id.get()), Some("abc")); + let clear = fixture.part(id.get(), CLEAR).expect("a search field with text shows the clear part"); + fixture.access(AccessActionKind::Click, &clear); + assert_eq!(text.borrow().as_str(), "", "the click emptied the text"); + assert_eq!(fixture.tree().value(id.get()), Some(""), "the field reads empty in the pass of the click"); +}