Under a modal layer, a dialog command reaches only instances inside the top modal or the canvas it holds open; Cmd+= in PagePreview leaves the PageView behind it alone

This commit is contained in:
aiongg
2026-11-12 14:32:41 +00:00
parent 9976cda32c
commit 47fdacf9d2
3 changed files with 47 additions and 3 deletions
+2 -1
View File
@@ -35,7 +35,8 @@ pub enum ModalRule {
/// Does not fire while a dialog is open.
#[default]
Blocked,
/// Fires from within a dialog and while none is open.
/// Fires from within a dialog and while none is open. While a modal layer is open, it reaches only an instance
/// inside the top modal layer, or the canvas that layer holds open.
InDialogs,
/// Fires whatever is open.
Always,
+35
View File
@@ -167,3 +167,38 @@ fn zoom_in_zooms_a_focused_view_with_animated_zoom() {
fixture.settle();
assert!(state.borrow().zoom > before, "Zoom In zooms: {before} -> {}", state.borrow().zoom);
}
#[trial]
fn zoom_keys_under_an_open_preview_leave_the_view_alone() {
let state = Rc::new(RefCell::new(PageViewState::default()));
let open = Rc::new(RefCell::new(false));
let (kept, opened) = (Rc::clone(&state), Rc::clone(&open));
let pages = DemoPages::new(3);
let mut at = 0_usize;
let mut fixture = Fixture::new(move |ui| {
let mut now = kept.borrow().clone();
PageView::new("Pages", &pages, &mut now, PAPER).options(LayoutOptions::ACROBAT).show(ui, |_, _| ());
*kept.borrow_mut() = now;
if *opened.borrow() {
PagePreview::new(&pages, &[0, 1, 2], &mut at, PAPER).show(ui);
}
});
fixture.room(vec2(900.0, 600.0));
fixture.settle();
focus_canvas(&mut fixture);
*open.borrow_mut() = true;
fixture.settle();
let before = state.borrow().zoom;
for (key, modifiers) in [
(Key::Equals, Modifiers::COMMAND),
(Key::Plus, Modifiers::COMMAND),
(Key::Minus, Modifiers::COMMAND),
(Key::Num0, Modifiers::COMMAND),
(Key::Plus, Modifiers::NONE),
(Key::Minus, Modifiers::NONE),
] {
fixture.key(key, modifiers);
fixture.settle();
assert_eq!(state.borrow().zoom, before, "{key:?} with {modifiers:?} under the preview");
}
}
@@ -230,8 +230,16 @@ impl Board {
let last = key.and_then(|key| self.last.get(&key));
let state = this.or(last);
let flags = resolve_flags(this.map(CommandState::flags), last.map(CommandState::flags));
let reached = declaring.is_some() || (!app && instance.is_some_and(|id| self.inside_modal.contains(&id)));
let modal = !(dialog_open && !reached && matches!(rule, Some(ModalRule::Blocked | ModalRule::Declared)));
let reached = declaring.is_some() || instance.is_some_and(|id| self.inside_modal.contains(&id));
let modal = !dialog_open
|| match rule {
None | Some(ModalRule::Always) => true,
// A modeless dialog that owns the keys has no modal root to reach into. The canvas a modal layer
// holds open is the one instance outside it that its view commands reach.
Some(ModalRule::InDialogs) => app || !self.modal_open || reached || instance.is_some_and(|id| Some(id) == self.held_open),
// `Blocked` and `Declared`.
Some(_) => reached,
};
let live = app || instance.is_some_and(|id| self.is_live(ctx, id));
let chord =
self.keymap.as_ref().and_then(|cache| cache.keymap.bindings(command).into_iter().find(|b| !b.trigger.double).map(|b| b.trigger.chord));