From 70d4172b6e4a01b8aafe1a1168852cef01f76238 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 18:21:59 +0000 Subject: [PATCH] Keys: the app's own canvas keeps the presses routed to it in egui's input A host-drawn region (focus::host_canvas) reads its keys from egui, so a key it keeps (Tab) must stay there. Stop::host marks it, and the key stage withdraws held presses only for framework components. --- crates/ui-contract/src/runtime/focus.rs | 2 +- crates/ui-contract/src/runtime/focus/registration.rs | 10 ++++++++++ crates/ui-contract/src/runtime/keys/route.rs | 10 +++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/ui-contract/src/runtime/focus.rs b/crates/ui-contract/src/runtime/focus.rs index 2c0eedcb52..c6b8ef6e6d 100644 --- a/crates/ui-contract/src/runtime/focus.rs +++ b/crates/ui-contract/src/runtime/focus.rs @@ -199,7 +199,7 @@ pub(crate) fn register_stop(ctx: &Context, stop: Stop) { /// With the canvas focused, Tab it keeps stays in egui too, and its edit set arrives as `Intent::Edit` /// (`keys::intents_of`), as for any focused stop. Call it each pass the canvas shows. pub fn host_canvas(ctx: &Context, id: Id, keys: KeyUse) { - register_stop(ctx, Stop::new(id, keys.with_chrome_key(true))); + register_stop(ctx, Stop::new(id, keys.with_chrome_key(true)).host()); } /// The keys of the document canvas `viewport` registered in its last pass (`KeyUse::chrome_key`), framework or the diff --git a/crates/ui-contract/src/runtime/focus/registration.rs b/crates/ui-contract/src/runtime/focus/registration.rs index 8d71fe2d29..328e007cf5 100644 --- a/crates/ui-contract/src/runtime/focus/registration.rs +++ b/crates/ui-contract/src/runtime/focus/registration.rs @@ -34,6 +34,9 @@ pub struct Stop { pub group: Option, /// The roving group of the innermost body the stop sits in, whether or not the stop joined it. pub body: Option, + /// The app's own egui widget (`focus::host_canvas`), which reads its keys from egui's input: the key stage leaves + /// the presses it routes to the stop there. + pub host: bool, } impl Stop { @@ -51,6 +54,7 @@ impl Stop { name: None, group: None, body: None, + host: false, } } @@ -108,6 +112,12 @@ impl Stop { self } + /// Marks the stop as the app's own egui widget. + pub fn host(mut self) -> Self { + self.host = true; + self + } + pub(crate) fn key(&self) -> StopKey { (self.id, self.part) } diff --git a/crates/ui-contract/src/runtime/keys/route.rs b/crates/ui-contract/src/runtime/keys/route.rs index 9388a5fe41..f39ce2cecb 100644 --- a/crates/ui-contract/src/runtime/keys/route.rs +++ b/crates/ui-contract/src/runtime/keys/route.rs @@ -110,7 +110,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting { push(&mut routed, focused, Intent::Edit(command), false); } let (shortcuts, held) = owned_shortcuts(ctx, target.as_ref(), &batch, &consumed); - withdraw_held(ctx, &batch, &held); + withdraw_held(ctx, target.as_ref(), &batch, &held); let pasted = batch.paste.as_deref().zip(focused).map(|(text, id)| (id, Arc::::from(text))); let escapes = craft_behavior::focus::route_escapes(batch.escapes, press_captured); for _ in 0..escapes.to_components { @@ -224,8 +224,12 @@ fn owned_shortcuts(ctx: &Context, target: Option<&StopRec>, batch: &Batch, consu } /// Takes the presses the focused component holds out of the running pass's egui input, where the app reads its own -/// keys: one press, one action. A held press whose release has not come yet leaves its release to the strip. -fn withdraw_held(ctx: &Context, batch: &Batch, held: &[bool]) { +/// keys: one press, one action. A held press whose release has not come yet leaves its release to the strip. The +/// app's own widget (`Stop::host`) reads its keys from egui, so its presses stay. +fn withdraw_held(ctx: &Context, target: Option<&StopRec>, batch: &Batch, held: &[bool]) { + if target.is_some_and(|rec| rec.stop.host) { + return; + } let presses: Vec<&Press> = batch.presses.iter().zip(held).filter(|(press, held)| **held && press.in_egui.is_some()).map(|(press, _)| press).collect(); if presses.is_empty() {