test: stage the dismissal gate the way the gesture actually holds it

The re-merge to main (9ac3fa22b) broke this test's premise. Main gained
`canvas_tool_menu::magnetic_drawing` (#11689): a right-click over a Magnetic
Lasso border in progress opens no menu, on the canvas and through the control
channel alike. So a menu can no longer be open over a live border, and the
test's right-click setup asserted behaviour that is now deliberately gone.

The `menu_dismiss_press` check on the hover block is therefore a guard rather
than a sequence a pointer can reach. The test stages the dismissal state
directly instead, with the button held: the flag is scoped to a held button (a
frame with every button up clears it), so a pointer-up frame would clear it
before the gate reads it and prove nothing. Holding the button also showed the
guard does suppress the hover, which the pointer-up version silently did not.

Two failures found while rebasing, both fixed here:
- the obsolete right-click setup (this commit);
- the pointer-up staging, which passed the flag only after the clear.
This commit is contained in:
Kaedo17 committed 2026-11-08 10:43:04 +08:00
1 parent 7212bb87b5
commit bfdf124639
1 file changed
+27 -26
@@ -418,41 +418,42 @@ fn on_the_canvas_the_border_follows_the_hovering_pointer_and_keys_work() {
assert!((area - 5600.0).abs() < 120.0, "{area}");
}
/// #9841: the hover moves are a pointer-only gesture: they must keep running on frames with no
/// button event, and they must be suppressed while a menu-dismissal press is being consumed.
/// #9841: the hover moves are a pointer-only gesture. Two things must hold: they keep running on
/// frames with no button event at all (the freeze the main-merge regression reintroduced), and a
/// consumed menu-dismissal gesture must not track the pointer.
///
/// A canvas menu cannot be open over a live border — `canvas_tool_menu::magnetic_drawing` refuses
/// one for a Magnetic Lasso border in progress (#11689), on the canvas and through the control
/// channel alike — so the `menu_dismiss_press` check on the hover block is a guard rather than a
/// sequence a pointer can reach. The dismissal state is staged directly here, with the button held
/// as the real gesture has it: the flag is scoped to a held button (a frame with every button up
/// clears it), so a pointer-up frame would clear it before the gate reads it and test nothing.
#[test]
fn on_the_canvas_hover_moves_survive_a_menu_dismissal_and_resume() {
let mut h = harness();
ui_click(&mut h, 52.0, 37.0);
assert!(h.state().ui.magnetic.active());
h.run_steps(2);
// A right-click opens the view menu without disturbing the border in progress.
let p = screen(&h, 90.0, 90.0);
h.event(egui::Event::PointerMoved(p));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(2);
assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the menu");
// The dismissal press well clear of the menu: inert, and the pointer-only hover must not run.
let far = screen(&h, 12.0, 140.0);
h.event(egui::Event::PointerMoved(far));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu");
let held = h.state().ui.magnetic.clone();
h.event(egui::Event::PointerMoved(screen(&h, 100.0, 36.0)));
h.run_steps(2);
assert_eq!(h.state().ui.magnetic, held, "a held dismissal press must not track the pointer");
// Released: the very next pointer move tracks again, with no button event at all.
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(2);
// Button up: the border follows the pointer with no button event at all.
ui_hover(&mut h, &[[52.0, 37.0], [100.0, 36.0]]);
let m = &h.state().ui.magnetic;
let end = m.live.last().or(m.path.last()).copied().unwrap();
assert!((end[0] - 100.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover resumes after the dismissal: {end:?}");
assert!((end[0] - 100.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover tracks with the button up: {end:?}");
// A consumed dismissal gesture with its button still down: the hover must not advance.
let far = screen(&h, 150.0, 130.0);
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
h.run_steps(1);
h.state_mut().ui.canvas_tool_menu_dismissed = true;
let held = h.state().ui.magnetic.clone();
ui_hover(&mut h, &[[100.0, 36.0], [130.0, 36.0]]);
assert_eq!(h.state().ui.magnetic, held, "a consumed dismissal gesture must not track the pointer");
// Released: the very next pointer move tracks again.
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(2);
ui_hover(&mut h, &[[130.0, 36.0], [120.0, 36.0]]);
let m = &h.state().ui.magnetic;
let end = m.live.last().or(m.path.last()).copied().unwrap();
assert!((end[0] - 120.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover resumes once released: {end:?}");
}
#[test]