Command board: declared edits reach the instance around the focus; a window layer can take unfocused keys

Outside the modal layers, a ModalRule::Declared app command now goes to the innermost
instance around the focus that published its state, as it already did inside a modal
layer: a list pane that declares Select All takes it while it holds the focus.
Trial: commands::board::a_declared_edit_reaches_the_instance_around_the_focus.

ViewportWindow::takes_unfocused_keys (opt-in, off by default) records the window's
layer with the board; while that layer is open, a key pressed in its viewport with
nothing focused goes to the instances in the window's body instead of the shell
and page roots, as a modal layer's root already gets them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-28 00:39:17 +00:00
1 parent 25a6fd365b
commit dd5c833799
4 files changed
+107 -12

No files matched your search

+14 -3
View File
@@ -40,6 +40,8 @@ impl Outcome for ViewportWindowOutput {
/// - **App-modal.** By default the window blocks nothing. [`app_modal`](ViewportWindow::app_modal) makes the app's
/// other windows ignore input while it is open, and a press on one raises this window.
/// - **Keys.** Escape asks to close an app-modal window, unless a popup in it is open; a tool window ignores it.
/// [`takes_unfocused_keys`](ViewportWindow::takes_unfocused_keys) gives a layer window the keys pressed with
/// nothing focused.
#[must_use = "show the window with `show`"]
#[derive(Pattern, Props)]
pub struct ViewportWindow {
@@ -54,12 +56,16 @@ pub struct ViewportWindow {
/// Keeps the window's place and size across runs under `key`.
#[prop]
remember: Option<SaveKey>,
/// Where the window is a layer, a key pressed in its viewport with nothing focused goes to the window's body, not
/// to the window under it: for a window that stands in front of the one it covers while it is shown.
#[prop(flag)]
takes_unfocused_keys: bool,
}
impl ViewportWindow {
/// A window titled `title` that blocks nothing.
pub fn new(title: impl Into<Label>) -> Self {
ViewportWindow { title: title.into(), modal: None, overlay: None, remember: None }
ViewportWindow { title: title.into(), modal: None, overlay: None, remember: None, takes_unfocused_keys: false }
}
/// Changes the layer the window falls back to, which starts as the resizable dialog layer: the smallest and
@@ -75,7 +81,7 @@ impl ViewportWindow {
/// Shows the window for this pass with `body` as its content.
pub fn show(self, ui: &mut Ui, mut body: impl FnMut(&mut Ui, &mut BodyCx<'_>)) -> ViewportWindowOutput {
let ViewportWindow { title, modal, overlay, remember } = self;
let ViewportWindow { title, modal, overlay, remember, takes_unfocused_keys } = self;
let mut dialog = Dialog::new(title).resizable(true);
if let Some(change) = overlay {
dialog = dialog.overlay(change);
@@ -89,7 +95,12 @@ impl ViewportWindow {
dialog = dialog.remember(key);
}
let mut open = true;
let shown = dialog.opened(Bind::bound(&mut open)).show(ui, |ui, cx| body(ui, cx));
let shown = dialog.opened(Bind::bound(&mut open)).show(ui, |ui, cx| {
if takes_unfocused_keys {
crate::runtime::commands::note_unfocused_keys_layer(ui.ctx());
}
body(ui, cx);
});
ViewportWindowOutput { response: shown.output.response, close_requested: shown.output.closed }
}
}