From 9f2fe6923e3609024cd8de9d4a50a412ea5fa909 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 22:50:46 +0000 Subject: [PATCH] Keys: the held-open canvas's Space is a press the held rule decides; a space a text field types is the field's --- crates/ui-contract/src/runtime/keys.rs | 3 +++ crates/ui-contract/src/runtime/keys/input.rs | 10 ++++++---- crates/ui-contract/src/runtime/keys/route.rs | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index 19620d5f2..d731f7cf7 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -75,6 +75,9 @@ struct Press { release: Option, /// The place in `Batch::texts` of the text the press typed. text: Option, + /// The Space of the canvas a dialog keeps open (`runtime::sampler`): no component's routing reads it, and only the + /// held rule decides whether its shortcut runs. + canvas: bool, } /// A key press, release or clipboard chord that the shortcut dispatcher may match, with the press that the diff --git a/crates/ui-contract/src/runtime/keys/input.rs b/crates/ui-contract/src/runtime/keys/input.rs index a440c8b6d..ebea9c8d0 100644 --- a/crates/ui-contract/src/runtime/keys/input.rs +++ b/crates/ui-contract/src/runtime/keys/input.rs @@ -206,9 +206,11 @@ impl Strip<'_> { false } else if key == Key::Space && self.canvas_space { // The canvas has Space (`runtime::sampler`): only the shortcut dispatcher reads it, so the dialog's - // focused control does not activate. + // focused control does not activate. Its shortcut follows the held rule: a space a text field types is + // the field's. + batch.presses.push(Press { key, mods, repeat, in_egui: None, release: None, text: None, canvas: true }); if !repeat { - batch.shortcuts.push(Shortcut { input: *input, phase: FirePhase::Press, press: None }); + batch.shortcuts.push(Shortcut { input: *input, phase: FirePhase::Press, press: Some(batch.presses.len() - 1) }); } false } else if (self.foreign && (bare_tab || escape)) || canvas_tab || canvas_edit { @@ -223,7 +225,7 @@ impl Strip<'_> { batch.tabs.push(TabPress { input: *input, repeat }); false } else if ctrl_tab { - batch.presses.push(Press { key, mods, repeat, in_egui: None, release: None, text: None }); + batch.presses.push(Press { key, mods, repeat, in_egui: None, release: None, text: None, canvas: false }); false } else if let Some(WindowShortcut::Pane { forward }) = window_shortcut { batch.nav.panes.push(forward); @@ -238,7 +240,7 @@ impl Strip<'_> { batch.menu.push(MenuKey::Letter(key.name().chars().next().unwrap_or('A'))); false } else { - batch.presses.push(Press { key, mods, repeat, in_egui: None, release: None, text: None }); + batch.presses.push(Press { key, mods, repeat, in_egui: None, release: None, text: None, canvas: false }); if !repeat { batch.shortcuts.push(Shortcut { input: *input, phase: FirePhase::Press, press: Some(batch.presses.len() - 1) }); } diff --git a/crates/ui-contract/src/runtime/keys/route.rs b/crates/ui-contract/src/runtime/keys/route.rs index 6adbf3979..54b25c399 100644 --- a/crates/ui-contract/src/runtime/keys/route.rs +++ b/crates/ui-contract/src/runtime/keys/route.rs @@ -54,7 +54,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting { // Whether a component took each text of the pass, as typing, type-ahead or digits. let mut taken_texts = vec![false; batch.texts.len()]; if let Some(rec) = &target { - for (press, taken) in batch.presses.iter().zip(&mut consumed) { + for (press, taken) in batch.presses.iter().zip(&mut consumed).filter(|(press, _)| !press.canvas) { *taken = if stale_repeat(&mut stale, press) { Taken::Yes } else { @@ -73,7 +73,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting { // With nothing focused, a plain Enter submits to the window, as an unfocused Escape cancels: a tool's pending // edit or a dialog's default button takes it. The arrows nudge the window's canvas content (a tool or the // session control on a canvas), unless a modal layer is open. - for (press, taken) in batch.presses.iter().zip(&mut consumed) { + for (press, taken) in batch.presses.iter().zip(&mut consumed).filter(|(press, _)| !press.canvas) { if press.key == Key::Enter && press.mods.is_none() && !press.repeat { push(&mut routed, None, Intent::Submit, false); *taken = Taken::Yes; @@ -268,7 +268,7 @@ pub fn focus_holds(ctx: &Context, chord: Chord) -> bool { if current(ctx, |stage| super::input::focused_claims(&record, stage)).contains(&chord) { return true; } - let press = Press { key: chord.key, mods: chord.mods, repeat: false, in_egui: None, release: None, text: None }; + let press = Press { key: chord.key, mods: chord.mods, repeat: false, in_egui: None, release: None, text: None, canvas: false }; let driven = Driven::of(ctx, &rec); let route = press_route(ctx, crate::runtime::windows::os_of(ctx), &rec, &press, driven.or_else(|| list_of_field(ctx, &rec))); let taken = !matches!(route, PressRoute::Free);