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 {