diff --git a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs index 77163189e0d..226a3031931 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs @@ -84,7 +84,17 @@ pub(crate) fn tap(h: &mut Harness<'_, Box>, key: Key, mods: Modif fn press(h: &mut Harness<'_, Box>, sc: &str) { let sc = parse(sc).unwrap_or_else(|| panic!("unparsable shortcut {sc}")); - tap(h, sc.logical_key, sc.modifiers); + // Two frames, not [`tap`]'s three: the runtime takes the key in the first and the app runs the command it fired + // in the second (`quick_shift_press` in `tool_shift_cycle_order_tests` measures the same for the tool letters). + // The third frame only drew the app again (#15941). + let m = platform(sc.modifiers); + h.input_mut().events.extend([ + egui::Event::ModifiersChanged(m), + egui::Event::Key { key: sc.logical_key, physical_key: None, pressed: true, repeat: false, modifiers: m }, + egui::Event::Key { key: sc.logical_key, physical_key: None, pressed: false, repeat: false, modifiers: m }, + egui::Event::ModifiersChanged(Modifiers::NONE), + ]); + h.run_steps(2); } /// Queue one press/release in one input frame, then let the runtime collect and the app dispatch it. @@ -349,6 +359,8 @@ fn every_displayed_shortcut_runs_its_menu_item() { fn every_kind_of_shortcut_dispatches_from_where_focus_usually_is() { let mut failures = Vec::new(); for place in [Place::Canvas, Place::LayersRow, Place::FocusedWidget, Place::OpacityField] { + // One app per place: the presses below include the panel toggles the runtime runs itself, so the next + // place could not count on the Layers panel still being there. let mut h = harness(); set_dry_run(&h.ctx, true); put_focus(&mut h, place); @@ -461,8 +473,8 @@ fn keys_run_their_commands() { set_dry_run(&h.ctx, false); // #352: ⌥[ ⌥] ⌥, ⌥. and ⇧⌥[ walk the Layers panel's rows. Rows, top to bottom: paint, Hello (type), group, - // in-group, Background. - let mut h = harness(); + // in-group, Background. The same app: the dry-run presses above ran no command, so the document is still the + // harness's own (#15941). assert_eq!(active_name(&h), "paint"); for (key, want) in [("Alt+[", "Hello"), ("Alt+[", "group"), ("Alt+[", "in-group"), ("Alt+]", "group"), ("Alt+,", "Background"), ("Alt+.", "paint")] { press(&mut h, key); @@ -512,11 +524,14 @@ fn keys_run_their_commands() { fn delete_key_targets() { // The selected layer, from the canvas or the Layers panel, in one undo step. for place in [Place::Canvas, Place::LayersRow] { + // One app per place: each key's delete is undone by the end of its case, so the next key starts from the + // same document without paying for another whole app (#15941). + let mut h = harness(); + put_focus(&mut h, place); for key in ["Delete", "Backspace"] { - let mut h = harness(); - put_focus(&mut h, place); let s = &mut h.state_mut().session; - s.execute("select.deselect", json!({})).unwrap(); + // The first case of the app deselects the harness's own selection; the ones after it start without one. + s.execute("select.deselect", json!({})).ok(); let adj = photocraft_doc::LayerId(s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap()["layer"].as_u64().unwrap()); h.run_steps(2); let before = names(&h); @@ -526,15 +541,21 @@ fn delete_key_targets() { assert_eq!(names(&h).len(), before.len() - 1, "{place:?} {key}: only it"); press(&mut h, "Cmd+Z"); assert_eq!(names(&h), before, "{place:?} {key}: one undo brings it back"); + // The undo's own log entry goes here: the next key of this app starts with an empty log, as the + // app-per-key version did. + take_log(&h.ctx); } } // The layer mask targeted: a selection fills the mask with the background colour, no selection deletes the mask. + // One app for both keys: the first case leaves the layer without a mask and without a selection, and the case + // puts both back before it starts (#15941). + let mut h = harness(); + put_focus(&mut h, Place::Canvas); for key in ["Delete", "Backspace"] { - let mut h = harness(); - put_focus(&mut h, Place::Canvas); let s = &mut h.state_mut().session; let layer = s.active().unwrap().active_layer.unwrap(); + s.execute("select.rect", json!({"x": 20, "y": 20, "width": 80, "height": 60})).unwrap(); s.execute("layer.layerMask.revealAll", json!({})).unwrap(); let sel = s.active().unwrap().doc.selection.as_ref().expect("the harness keeps a selection").content_bounds(); let (x, y) = ((sel.x0 + sel.x1) / 2, (sel.y0 + sel.y1) / 2); diff --git a/crates/ui-egui/src/reset_tip_tests.rs b/crates/ui-egui/src/reset_tip_tests.rs index 44236f10838..9b6e739a744 100644 --- a/crates/ui-egui/src/reset_tip_tests.rs +++ b/crates/ui-egui/src/reset_tip_tests.rs @@ -112,9 +112,13 @@ fn starting(app: &PhotocraftApp, tool: Tool) -> Tip { #[test] fn each_tool_resets_and_first_uses_its_own_tip() { + // One app for the two reset commands of all sixteen tools. Each case picks the tool and scrambles the brush + // before it invokes, and `tool.reset` / `tool.resetAll` work through `fresh_brush` for the tool in front of them, + // so a case never needs an app of its own: starting the app (document, panels, views) was the cost of a case + // here, 80 of them (#15941). + let mut a = app(); for (tool, first_use) in ROWS { // Reset Tool. - let mut a = app(); pick(&mut a, tool); scramble(&mut a); assert_ne!(live(&a), starting(&a, tool), "{tool:?}: the scrambled tip is not its starting tip"); @@ -122,12 +126,10 @@ fn each_tool_resets_and_first_uses_its_own_tip() { assert_eq!(live(&a), starting(&a, tool), "{tool:?}: Reset Tool"); // Reset All Tools with the tool active, then with it picked later. - let mut a = app(); pick(&mut a, tool); scramble(&mut a); invoke(&mut a, "tool.resetAll", json!({"confirmed": true})); assert_eq!(live(&a), starting(&a, tool), "{tool:?}: Reset All Tools, active"); - let mut a = app(); pick(&mut a, tool); scramble(&mut a); pick(&mut a, other(tool)); @@ -136,7 +138,6 @@ fn each_tool_resets_and_first_uses_its_own_tip() { assert_eq!(live(&a), starting(&a, tool), "{tool:?}: Reset All Tools, picked later"); // Other tools keep their brushes through Reset Tool. - let mut a = app(); pick(&mut a, other(tool)); scramble(&mut a); let kept = live(&a); @@ -145,7 +146,8 @@ fn each_tool_resets_and_first_uses_its_own_tip() { let theirs = a.ui.tool_brushes.iter().find(|(t, _)| *t == other(tool)).map(|(_, b)| tip(b)); assert_eq!(theirs, Some(kept), "{tool:?}: {:?} keeps its tip", other(tool)); - // First use, after another tool's tip; its own tip is then kept across tool switches. + // First use, after another tool's tip; its own tip is then kept across tool switches. The tool must not have + // been picked before, so this case keeps an app of its own. let Some(rule) = first_use else { continue }; let mut a = app(); pick(&mut a, other(tool));