Filter preview locator: finish open tool drags, end held presses

Two more #9648 review points on the ui.pointer path.

- A tool drag begun before the dialog opened got its release but lost
  its moves under the dialog, so a Brush stroke spanning the opening
  committed a different path. While a tool drag is open, its moves now
  reach the tool too, not only the release.
- The held locator press (__pvPointerDown) stayed set when the primary
  release went elsewhere (Space held, another dialog on top, the dialog
  closed), so a later hover moved the preview with no button down. Any
  primary release now clears it in every open dialog before the modal
  handlers run, without consuming the event.

Tests: the spanning Brush stroke keeps the points it got under the
dialog and the preview stays put; a Space-held release and a release on
a Color Picker over the dialog both end the press, so a later move
doesn't centre.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ljkxandClaude Opus 5.5 committed 2026-10-28 19:40:05 +01:00
1 parent 29c3b4cea4
commit faa70764ee
3 files changed
+47 -6

No files matched your search

+8 -3
View File
@@ -1152,6 +1152,11 @@ fn parse_pointer_event(i: usize, e: &Value) -> std::result::Result<PointerSample
/// Whether a modal tool, picker or context menu took the event instead of the canvas.
fn pointer_event_intercepted(app: &mut PhotocraftApp, ctx: &egui::Context, g: &PointerGesture, s: &PointerSample) -> bool {
// A primary release ends a held locator press wherever it lands (another dialog on top, Space
// held, the dialog closed), so a later hover never drags the preview; the event goes on.
if matches!(s.ev, ToolEvent::Up { .. }) && !g.secondary && !g.middle {
crate::filter_preview_ui::clear_pointer_state(app);
}
pointer_eyedropper_took(app, ctx, g, s)
|| color_range_took(app, g, s)
|| preview_locator_took(app, g, s)
@@ -1160,14 +1165,14 @@ fn pointer_event_intercepted(app: &mut PhotocraftApp, ctx: &egui::Context, g: &P
/// A filter dialog with a preview window on top: the image is its locator, as for the mouse
/// (#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 release that ends a
/// tool gesture begun before the dialog opened.
/// 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.
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 { .. }));
if up && !g.secondary && !g.middle && app.drag.is_some() {
if !down && !g.secondary && !g.middle && app.drag.is_some() {
return false;
}
if !g.secondary && !g.middle && !g.space {
@@ -197,6 +197,14 @@ pub(crate) fn pointer_event(app: &mut PhotocraftApp, down: bool, up: bool, x: f6
}
}
/// A primary `ui.pointer` release, wherever it went: no locator press stays held in any open
/// dialog, even one that was not on top or not taking the pointer when the button came up.
pub(crate) fn clear_pointer_state(app: &mut PhotocraftApp) {
for d in &mut app.ui.dialogs {
d.fields.remove(POINTER_DOWN_FIELD);
}
}
/// The zoom levels the − / + buttons step through, like the Filter Gallery's.
const ZOOM_STEPS: [f32; 7] = [0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0];
@@ -226,7 +226,8 @@ fn ui_pointer_centres_only_while_the_press_is_held() {
assert!(near(centre(&h), [80.0, 60.0]), "after the release a move is a hover again: {:?}", centre(&h));
}
/// A Brush stroke an agent began before the dialog opened still ends: its release reaches the tool.
/// A Brush stroke an agent began before the dialog opened still ends along its own path: its moves
/// and release reach the tool, not the locator.
#[test]
fn a_tool_gesture_begun_before_the_dialog_still_ends_under_it() {
let mut h = harness(None, 0.0);
@@ -236,8 +237,35 @@ fn a_tool_gesture_begun_before_the_dialog_still_ends_under_it() {
crate::filter_dialog::open(h.state_mut(), "filter.sharpen.smartSharpen").unwrap();
h.run_steps(2);
assert!(h.state().drag.is_some(), "the stroke is still open under the dialog");
pointer(&mut h, json!([{"kind": "up", "x": 80, "y": 30}]));
pointer(&mut h, json!([{"kind": "move", "x": 80, "y": 120}, {"kind": "move", "x": 120, "y": 120}]));
let points = h.state().drag.as_ref().map(|d| d.points.clone()).unwrap_or_default();
assert!(points.iter().any(|p| p[1] > 100.0), "the moves under the dialog reached the stroke: {points:?}");
pointer(&mut h, json!([{"kind": "up", "x": 120, "y": 120}]));
assert!(h.state().drag.is_none(), "the release reached the Brush");
assert_eq!(edits(&h).1, before.1 + 1, "the stroke is one history step");
assert!(near(centre(&h), [200.0, 150.0]), "the release is not a locator press: {:?}", centre(&h));
assert!(near(centre(&h), [200.0, 150.0]), "the stroke's moves and release are not locator presses: {:?}", centre(&h));
}
/// A release the locator doesn't take (Space held, or another dialog on top) still ends its press,
/// so a later hover doesn't drag the preview with no button down.
#[test]
fn a_release_elsewhere_ends_the_locator_press() {
let mut h = harness(Some("filter.sharpen.smartSharpen"), 0.0);
pointer(&mut h, json!([{"kind": "down", "x": 40, "y": 30}]));
assert!(near(centre(&h), [40.0, 30.0]), "{:?}", centre(&h));
let (req, _rx) = crate::control::ControlRequest::new("ui.pointer", json!({"events": [{"kind": "up", "x": 40, "y": 30}], "space": true}));
let _ = crate::control::handle(h.state_mut(), &egui::Context::default(), &req);
h.run_steps(2);
pointer(&mut h, json!([{"kind": "move", "x": 120, "y": 90}]));
assert!(near(centre(&h), [40.0, 30.0]), "a Space-held release ends the press: {:?}", centre(&h));
// The release lands on a Color Picker opened over the dialog.
pointer(&mut h, json!([{"kind": "down", "x": 60, "y": 50}]));
assert!(near(centre(&h), [60.0, 50.0]), "{:?}", centre(&h));
let picker = crate::color_picker_ui::open(h.state_mut(), "foreground");
pointer(&mut h, json!([{"kind": "up", "x": 60, "y": 50}]));
h.state_mut().ui.close_dialog(picker);
h.run_steps(2);
pointer(&mut h, json!([{"kind": "move", "x": 120, "y": 90}]));
assert!(near(centre(&h), [60.0, 50.0]), "a release on another dialog ends the press: {:?}", centre(&h));
}