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.
This commit is contained in:
Dylan M. Taylor
2026-11-23 07:43:54 -05:00
parent efe4040927
commit 4854e2cff6
2 changed files with 25 additions and 0 deletions
+3
View File
@@ -438,6 +438,9 @@ impl<C: Codec + Clone + 'static> 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");
}
}
@@ -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");
}