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.
This commit is contained in:
aiongg
2026-11-12 18:22:18 +00:00
parent 978e702874
commit 70d4172b6e
3 changed files with 18 additions and 4 deletions
+1 -1
View File
@@ -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
@@ -34,6 +34,9 @@ pub struct Stop {
pub group: Option<Id>,
/// The roving group of the innermost body the stop sits in, whether or not the stop joined it.
pub body: Option<Id>,
/// 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)
}
+7 -3
View File
@@ -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::<str>::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() {