mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 07:35:02 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user