From aa2983906938031625eaec83a855b6a826b30a50 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 14:31:13 -0800 Subject: [PATCH] Tools: the Three-Point Arc tool places a point with the keys held at release A release at the position of the last pointer event kept the point that the earlier keys had constrained. Pressing the third point with Shift and letting go with Shift and Alt drew the direction from the second end but kept the 45-degree step taken from the first. The release now places the point again when Shift or Alt changed, for both ends and the third point. A change of keys alone does not make the first press a drag, so a click that snaps to an anchor and is let go with Shift changed places only the first end. --- crates/tools/src/three_point_arc.rs | 20 ++++++----- crates/tools/src/three_point_arc/tests.rs | 41 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/crates/tools/src/three_point_arc.rs b/crates/tools/src/three_point_arc.rs index 67ce63e03f..c25a3dca05 100644 --- a/crates/tools/src/three_point_arc.rs +++ b/crates/tools/src/three_point_arc.rs @@ -58,8 +58,8 @@ pub struct ThreePointArcTool { pointer: Option, /// Alt was held at the last pointer event: in direction mode, the direction is at the second end. at_end: bool, - /// Where the pressed pointer was at its last event, before snapping. - raw: Option, + /// Where the pressed pointer was at its last event, before snapping, and the keys held then. + raw: Option<(Point, Mods)>, } /// The arc from `start` to `end` shaped by `third`, as `shape.threePointArc` draws it: through @@ -106,12 +106,14 @@ impl ThreePointArcTool { } } - /// The pressed pointer moved to `ev`: the point being placed follows it. + /// The pressed pointer moved to `ev`, or Shift or Alt changed: the point being placed follows + /// it. A change of keys alone does not make the press a drag. fn follow(&mut self, cx: &ToolContext, ev: &PointerEvent) { - self.raw = Some(ev.pos); + let moved = self.raw.is_none_or(|(p, _)| p != ev.pos); + self.raw = Some((ev.pos, ev.mods)); match &mut self.press { Some(Press::Start { at, dragged }) => { - *dragged |= ev.pos.distance(*at) >= cx.tol(DRAG_PX); + *dragged |= moved && ev.pos.distance(*at) >= cx.tol(DRAG_PX); let leave = Leave::segment(cx, *at, ev.mods.shift); self.pointer = Some(self.snap.drag(cx, ev.pos, Some(&leave))); } @@ -149,7 +151,7 @@ impl Tool for ThreePointArcTool { vec![] } PointerKind::Down => { - self.raw = Some(ev.pos); + self.raw = Some((ev.pos, ev.mods)); let leave = self.leave(cx, ev.mods); match (self.start, self.end) { (None, _) => { @@ -180,8 +182,10 @@ impl Tool for ThreePointArcTool { vec![] } PointerKind::Up => { - // A release away from the last drag event places the point where it is let go. - if self.press.is_some() && self.raw != Some(ev.pos) { + // A release away from the last drag event places the point where it is let go, and + // a release with Shift or Alt changed places it as those keys keep it. + let same = self.raw.is_some_and(|(p, m)| p == ev.pos && (m.shift, m.alt) == (ev.mods.shift, ev.mods.alt)); + if self.press.is_some() && !same { self.follow(cx, ev); } match (self.press.take(), self.start, self.pointer) { diff --git a/crates/tools/src/three_point_arc/tests.rs b/crates/tools/src/three_point_arc/tests.rs index 88e63dc1b4..d7c35ddc8b 100644 --- a/crates/tools/src/three_point_arc/tests.rs +++ b/crates/tools/src/three_point_arc/tests.rs @@ -209,6 +209,47 @@ fn a_point_is_placed_where_the_press_is_let_go() { assert_eq!(t.end, Some(Point::new(380.0, 300.0))); } +/// A release with Shift or Alt changed since the press places the point as the keys at the +/// release keep it, even where the pointer did not move. +#[test] +fn a_release_places_the_point_with_the_keys_held_then() { + let (d, _) = doc_with_rect(); + let (s, p) = (Selection::default(), paint()); + let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) }; + let mut t = ThreePointArcTool::default(); + let (none, shift) = (Mods::default(), Mods { shift: true, ..Mods::default() }); + // The second end: pressed without Shift, let go with it. + click(&mut t, &cx, (300.0, 300.0)); + t.pointer(&cx, &ev(PointerKind::Down, (380.0, 306.0), none)); + t.pointer(&cx, &ev(PointerKind::Up, (380.0, 306.0), shift)); + assert_eq!(t.end.map(|e| e.y), Some(300.0), "{:?}", t.end); + // The third point in direction mode: pressed with Shift, let go with Shift and Alt, so the + // direction line keeps to 45° steps from the second end. + t.set_option("direction", &json!(true)); + let both = Mods { alt: true, ..shift }; + t.pointer(&cx, &ev(PointerKind::Down, (303.0, 250.0), shift)); + let acts = t.pointer(&cx, &ev(PointerKind::Up, (303.0, 250.0), both)); + let [Action::Exec(_, params)] = acts.as_slice() else { panic!("{acts:?}") }; + let at = |key: &str, i: usize| params[key][i].as_f64().unwrap_or(f64::NAN); + let (dx, dy) = (at("toward", 0) - at("end", 0), at("toward", 1) - at("end", 1)); + assert!(params["at"] == "end" && (dx.abs() - dy.abs()).abs() < 1e-9, "{params}"); +} + +/// A first click that snaps to the rectangle's corner, 3 pt from the pointer, and is let go with +/// Shift changed places only the first end: a change of keys alone is not a drag. +#[test] +fn a_click_let_go_with_shift_changed_is_not_a_drag() { + let (d, _) = doc_with_rect(); + let (s, p) = (Selection::default(), paint()); + let cx = cx(&d, &s, &p); + let g = Point::new(200.0, 200.0); + let off = (203.0, 201.0); + let mut t = ThreePointArcTool::default(); + t.pointer(&cx, &ev(PointerKind::Down, off, Mods::default())); + t.pointer(&cx, &ev(PointerKind::Up, off, Mods { shift: true, ..Mods::default() })); + assert_eq!((t.start, t.end), (Some(g), None)); +} + /// Shift keeps the second end at 45° steps from the first. #[test] fn shift_keeps_the_second_end_at_45_degree_steps() {