From 8167b69fd910e1867f0d572e0b3d00a805dd9d6e Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 22:49:51 +0000 Subject: [PATCH] Key stage: a canvas tool's state-dependent claims hold while a non-text member of the canvas's arena (a frame part) is focused --- crates/ui-contract/src/runtime/focus.rs | 3 +++ crates/ui-contract/src/runtime/focus/nav.rs | 1 + crates/ui-contract/src/runtime/keys/input.rs | 2 +- crates/ui-contract/src/runtime/keys/route.rs | 14 ++++++++++---- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/runtime/focus.rs b/crates/ui-contract/src/runtime/focus.rs index b5e754985..7bc26a8ef 100644 --- a/crates/ui-contract/src/runtime/focus.rs +++ b/crates/ui-contract/src/runtime/focus.rs @@ -72,6 +72,9 @@ pub(crate) struct FocusedRecord { pub(crate) claims: Vec, /// The component of the focused stop: only its state-dependent claims hold. pub(crate) focused: Option, + /// The arena root of the focused stop when the stop is a non-text member of an arena (a part of a canvas's frame + /// overlay): the root's state-dependent claims hold too, so a canvas tool's keys work with a part focused. + pub(crate) root: Option, /// The focused stop switches pages with Ctrl+Tab. pub(crate) pages: bool, pub(crate) menu_bar: bool, diff --git a/crates/ui-contract/src/runtime/focus/nav.rs b/crates/ui-contract/src/runtime/focus/nav.rs index 42190ceeb..0e271bec3 100644 --- a/crates/ui-contract/src/runtime/focus/nav.rs +++ b/crates/ui-contract/src/runtime/focus/nav.rs @@ -678,6 +678,7 @@ pub(super) fn end(state: &mut State, focused: Option, on_app_widget: bool, f state.record = super::FocusedRecord { claims: keys.map(|keys| keys.claims.to_vec()).unwrap_or_default(), focused: stop.as_ref().map(|stop| stop.id), + root: stop.as_ref().filter(|stop| stop.root != stop.id && !stop.text).map(|stop| stop.root), pages: stop.as_ref().is_some_and(|stop| stop.role.pages), keys, menu_bar: std::mem::take(&mut state.menu_bar), diff --git a/crates/ui-contract/src/runtime/keys/input.rs b/crates/ui-contract/src/runtime/keys/input.rs index 6b3a046b4..27abaff7c 100644 --- a/crates/ui-contract/src/runtime/keys/input.rs +++ b/crates/ui-contract/src/runtime/keys/input.rs @@ -344,7 +344,7 @@ enum PressUse { /// bare End where it declares `EndKey::EndMode`. pub(super) fn focused_claims(record: &focus::FocusedRecord, stage: &Stage) -> Vec { let mut claims = record.claims.clone(); - claims.extend(stage.claims.iter().filter(|(owner, _)| Some(*owner) == record.focused).map(|(_, chord)| *chord)); + claims.extend(stage.claims.iter().filter(|(owner, _)| Some(*owner) == record.focused || Some(*owner) == record.root).map(|(_, chord)| *chord)); // A bare End belongs to a stop that declares `EndKey::EndMode`: it reads the key as a claimed chord and toggles its // mode, so no collection navigation or scroll owner takes it as a move to the end. if record.keys.is_some_and(|keys| keys.end == EndKey::EndMode) { diff --git a/crates/ui-contract/src/runtime/keys/route.rs b/crates/ui-contract/src/runtime/keys/route.rs index 363c1b346..5604babea 100644 --- a/crates/ui-contract/src/runtime/keys/route.rs +++ b/crates/ui-contract/src/runtime/keys/route.rs @@ -22,15 +22,15 @@ use std::sync::Arc; pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting { let os = crate::runtime::windows::os_of(ctx); let target = focus::focused_rec(ctx); - let (batch, nodes, captures) = current(ctx, |stage| { + let (batch, nodes, captures, held_claims) = current(ctx, |stage| { stage.routed.clear(); stage.contexts.clear(); stage.claimed.clear(); stage.activated.clear(); - stage.claims.clear(); + let held_claims = std::mem::take(&mut stage.claims); stage.last_open_edits = std::mem::take(&mut stage.open_edits); stage.last_nodes = std::mem::take(&mut stage.nodes); - (std::mem::take(&mut stage.batch), stage.last_nodes.clone(), std::mem::take(&mut stage.captures)) + (std::mem::take(&mut stage.batch), stage.last_nodes.clone(), std::mem::take(&mut stage.captures), held_claims) }); let modal = overlay::any_open(ctx, overlay::OpenFilter::Modal); let stale_repeat = |stale: &mut bool, press: &Press| { @@ -96,6 +96,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting { } } let focused = target.as_ref().map(|rec| rec.stop.id); + let root = target.as_ref().filter(|rec| rec.stop.root != rec.stop.id && !rec.stop.text).map(|rec| rec.stop.root); // The web sends a chord's key press and its clipboard event: the command reaches the component once. let mut clips = batch.clips.clone(); clips.dedup(); @@ -125,7 +126,12 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting { for chord in &batch.claimed { match driven.and_then(|driven| driven.intent_of(chord)) { Some(intent) => push(&mut routed, driven.map(|driven| driven.list), intent, false), - None => claimed.extend(captures.iter().find(|(_, held)| held == chord).map(|(owner, _)| *owner).or(focused).map(|id| (id, *chord))), + None => { + // A capture's owner, else the claim's: the focused component's own, then its arena root's. + let held = |owner: Option| held_claims.iter().find(|(id, held)| Some(*id) == owner && held == chord).map(|(id, _)| *id); + let owner = captures.iter().find(|(_, held)| held == chord).map(|(owner, _)| *owner); + claimed.extend(owner.or_else(|| held(focused)).or_else(|| held(root)).or(focused).map(|id| (id, *chord))); + } } } for request in &batch.access {