From c76b8ca56cb1e74992eef8c6efd26149212e9d1e Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 16:45:31 +0000 Subject: [PATCH] Palette in-place face: the field takes the key focus on every closed-to-open transition, not only the first stage appearance --- crates/ui-patterns/src/patterns/panels/palette.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ui-patterns/src/patterns/panels/palette.rs b/crates/ui-patterns/src/patterns/panels/palette.rs index 02e6799ef..58056d058 100644 --- a/crates/ui-patterns/src/patterns/panels/palette.rs +++ b/crates/ui-patterns/src/patterns/panels/palette.rs @@ -238,16 +238,18 @@ impl<'a> CommandPalette<'a> { let _ = open.reborrow().write(cx, &EditEvent::set(Mixed::Same(false), true, name, None)); is_open = true; } + // The closed-to-open transition, whichever route made it: the field takes the key focus in this pass. + let was_open = std::mem::replace(&mut cx.memory::().0, is_open); + let opening = is_open && !was_open; if !is_open { return; } // The container exists only while the palette is open, so its memory starts empty at each opening. Row::new().show(ui, |ui, inner| { - if inner.appeared() { + if opening { focus::request(&ctx, FocusTarget::Id(field_id)); } let session = inner.memory::(); - eprintln!("DIAG escape_and_a_press_outside_close_the_in_place_face_and_the_fallback_row_carries_the_query: query={:?}", session.query); let field = TextField::search(words.palette_search.clone(), Bind::bound(&mut session.query)) .placeholder(face_hint.clone()) .id(field_id) @@ -275,6 +277,10 @@ impl<'a> CommandPalette<'a> { } } +/// Whether the in-place face was open in the pass before, so the pass that opens it is known. +#[derive(Clone, Default)] +struct WasOpen(bool); + /// What a pass of the list chose. #[derive(Default)] struct Chosen {