From 82ad894e090cd26a3ca6dbfba92eda2540bd4e08 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Thu, 26 Nov 2026 21:12:12 +0100 Subject: [PATCH] Checkbox sweep: a release that gives way to a new press claims no drag it never started Reviewer finding: once a press's `Down` was reported, a far release with no move before it marked the press as dragging and held the release for the `DragStart` it still owed. A new press in the same batch ended it first, so the parts read a dragging `Release` with no `DragStart` before it. A release that gives way to a new press now reports the drag only when the parts were told its start (`Open::drag_reported`), so a press reads `Down`, a `Release`, or `DragStart` then `Drag` and `Release`. Where the button went up stays in `Release::pos`, and a release past slop is no click either way. Regression: `Down` reported, then a far release with no move and a new press in the same batch. --- crates/behavior/src/press.rs | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index 960570759c..a9a6e5a92d 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -721,11 +721,14 @@ impl PressMachine { } PointerEvent::Pressed { button, pos: at, time, clicks } => { pos = at; - // A release held for the next pass gives way to a new press; it ends in this pass. + // A release held for the next pass gives way to a new press; it ends in this pass. A drag whose + // start that pass still owed was never reported, so the release is no drag either: every part reads + // `Down`, a `Release`, or `DragStart` then `Drag`, never a drag's end that never began. The press's + // target hears where the button went up in `Release::pos`, and no click is at that distance. if let Some(open) = self.open && let Some((up, click)) = open.released_at { - released = Some((open.target, open.start, up, open.dragging, click, open.silent)); + released = Some((open.target, open.start, up, open.drag_reported, click, open.silent)); self.open = None; } // A secondary press during an open primary press goes beside it, to the context target `pick` gives @@ -1183,6 +1186,41 @@ mod tests { assert_eq!(phases(&[&[press(0.0, 1.0)], &[up(SLOP / 2.0)]], PASSES), "D R!", "a jump within slop is the shape's click"); } + /// A press whose button jumped far and came up in a batch that also pressed again: the release ends the press in + /// that pass, so the `DragStart` the jump owed never comes. The release is then no drag either, and the parts read + /// `Down` then a `Release` with no drag between them: a drag's end that never began would leave a part that tracks + /// a drag holding a press forever. The new press reports its `Down` in the next pass. + #[test] + fn a_jump_release_that_gives_way_to_a_new_press_reports_no_drag() { + let sense = Sense::CLICK | Sense::DRAG; + let far = SLOP * 4.0; + let jumped = [up(far), press(far, 1.1)]; + assert_eq!(phases(&[&[press(0.0, 1.0)], &jumped[..], &[]], sense), "D R D", "the release ends the press with no drag of its own"); + + let mut machine = PressMachine::new(); + pass(&mut machine, &[press(0.0, 1.0)], sense); + let end = pass(&mut machine, &jumped, sense); + assert!( + matches!(end.phase, Some(PressPhase::Release { start, pos, click: false }) if start.origin == pos2(0.0, 0.0) && pos == pos2(far, 0.0)), + "{:?}", + end.phase + ); + assert!(!end.dragging, "the press never reported its drag's start, so its release claims none"); + assert_eq!(end.activated, None, "a jump release past slop is no click"); + assert!(!machine.dragging(), "the new press is no drag either"); + pass(&mut machine, &[], sense); + let next = machine.open.map(|open| open.start.origin); + assert!(matches!(next, Some(place) if place == pos2(far, 0.0)), "the new press is open from where it went down"); + + // A press that did report its drag's start keeps its drag's end, whatever gives way to it. + let mut machine = PressMachine::new(); + pass(&mut machine, &[press(0.0, 1.0)], sense); + assert!(matches!(pass(&mut machine, &[up(far)], sense).phase, Some(PressPhase::DragStart { .. })), "the jump starts the drag"); + let end = pass(&mut machine, &[up(far), press(far, 1.3)], sense); + assert!(matches!(end.phase, Some(PressPhase::Release { click: false, .. })), "{:?}", end.phase); + assert!(end.dragging, "the release ends the drag the part saw start"); + } + /// A jump release past slop on a target that only clicks abandons the click as a move past slop does: the release /// is reported with no click and nothing activates. #[test]