diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index c4a689398e..c102aa6f09 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -1228,15 +1228,17 @@ fn pointer_event_intercepted(app: &mut PhotocraftApp, ctx: &egui::Context, g: &P /// (#9648). A press or drag with the primary button centres the window there; every other event /// is consumed too, so nothing reaches the tool under the dialog, except the moves and release of /// a tool gesture begun before the dialog opened, which finish it along the path they draw. A Crop -/// frame or Straighten drag is one too, though the Crop tool keeps it apart from `app.drag`. +/// frame or Straighten drag is one too, though the Crop tool keeps it apart from `app.drag`. While +/// one is open, a second primary press (no mouse can make one) is dropped: it neither centres the +/// window nor reaches the tool, so no locator press splits the gesture's moves and release. fn preview_locator_took(app: &mut PhotocraftApp, g: &PointerGesture, s: &PointerSample) -> bool { if crate::filter_preview_ui::locator(app).is_none() { return false; } let (down, up) = (matches!(s.ev, ToolEvent::Down { .. }), matches!(s.ev, ToolEvent::Up { .. })); let tool_gesture = app.drag.is_some() || app.crop.drag.is_some() || app.crop.straighten.line.is_some(); - if !down && !g.secondary && !g.middle && tool_gesture { - return false; + if !g.secondary && !g.middle && tool_gesture { + return down; } if !g.secondary && !g.middle && !g.space { crate::filter_preview_ui::pointer_event(app, down, up, s.x, s.y); diff --git a/crates/ui-egui/src/filter_preview_locator_tests.rs b/crates/ui-egui/src/filter_preview_locator_tests.rs index 0e82c51986..cd099fab36 100644 --- a/crates/ui-egui/src/filter_preview_locator_tests.rs +++ b/crates/ui-egui/src/filter_preview_locator_tests.rs @@ -282,9 +282,34 @@ fn a_crop_drag_begun_before_the_dialog_still_ends_under_it() { crate::filter_dialog::open(h.state_mut(), "filter.sharpen.smartSharpen").unwrap(); h.run_steps(2); pointer(&mut h, json!([{"kind": "move", "x": 160, "y": 120}])); + let r = h.state().ui.crop_rect.expect("a crop frame"); + assert!(r[2] > 150.0 && r[3] > 110.0, "the move under the dialog reached the frame before the release: {r:?}"); pointer(&mut h, json!([{"kind": "up", "x": 160, "y": 120}])); assert!(h.state().crop.drag.is_none(), "the release reached the Crop tool"); let r = h.state().ui.crop_rect.expect("a crop frame"); assert!(r[2] > 150.0 && r[3] > 110.0, "the moves under the dialog reached the frame: {r:?}"); assert!(near(centre(&h), [200.0, 150.0]), "the drag's moves and release are not locator presses: {:?}", centre(&h)); } + +/// A second press while an agent's Brush stroke is still open (no mouse can make one) is dropped: +/// it neither centres the preview nor reaches the Brush, and the stroke's own moves and release +/// still finish it. +#[test] +fn a_press_during_an_open_tool_gesture_is_dropped() { + let mut h = harness(None, 0.0); + let before = edits(&h); + pointer(&mut h, json!([{"kind": "down", "x": 40, "y": 30}, {"kind": "move", "x": 80, "y": 30}])); + crate::filter_dialog::open(h.state_mut(), "filter.sharpen.smartSharpen").unwrap(); + h.run_steps(2); + let points = h.state().drag.as_ref().map(|d| d.points.len()).unwrap_or_default(); + pointer(&mut h, json!([{"kind": "down", "x": 300, "y": 200}])); + assert!(near(centre(&h), [200.0, 150.0]), "the extra press doesn't centre the preview: {:?}", centre(&h)); + assert_eq!(h.state().drag.as_ref().map(|d| d.points.len()), Some(points), "nor does it reach the open stroke"); + pointer(&mut h, json!([{"kind": "move", "x": 80, "y": 120}])); + assert!(near(centre(&h), [200.0, 150.0]), "the stroke's moves are not a locator drag: {:?}", centre(&h)); + let pts = h.state().drag.as_ref().map(|d| d.points.clone()).unwrap_or_default(); + assert!(pts.iter().any(|p| p[1] > 100.0), "the move reached the stroke: {pts:?}"); + pointer(&mut h, json!([{"kind": "up", "x": 80, "y": 120}])); + assert!(h.state().drag.is_none(), "the release ended the stroke"); + assert_eq!(edits(&h).1, before.1 + 1, "the stroke is one history step"); +}