From 4a6ea8a9840f21e9f949779fe00de483a886d4b9 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 24 Nov 2026 00:57:49 +0700 Subject: [PATCH] ui-contract: a text part asks where the keyboard goes back to only once it held the focus or keeps a selection for a menu, so a part that never held the focus reads no focus in its run: the replay audit found a memoized view whose field read the focus only when another stop had it --- crates/ui-contract/src/contract/text.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index 058bad960..46da94442 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -439,8 +439,11 @@ fn prepare(core: &mut CxCore<'_>, ui: &mut Ui, decl: &TextPart, state: &mut Text let ink = if enabled { ink } else { crate::style::rgba_color(crate::runtime::env::Env::of(ui).tokens.color.text.disabled) }; let held = core.popup(EDIT_MENU).is_open_in(core); // A menu bar or a menu the keyboard goes back to the part from has the focus: their Cut and Copy act on the - // selection the part keeps for them. - let returns_here = crate::runtime::focus::focused_stop(&ctx) + // selection the part keeps for them. Only a part that had the focus last pass, or keeps a selection already, can be + // gone back to: asking reads the focus, which a part that never held it has not read, so its replay stays true. + let returns_here = (state.focused || state.held_selection.is_some()) + .then(|| crate::runtime::focus::focused_stop(&ctx)) + .flatten() .filter(|(focused, _)| *focused != id) .and_then(|(focused, _)| crate::runtime::focus::returning(&ctx, focused)) .is_some_and(|((to, _), _)| to == id);