From 6e8a8e8cdbaf0384e9490e47cce355faf2ca1d76 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 15:18:56 -0800 Subject: [PATCH 1/2] Shapes: a Circle tool release near the press is a click, also after a drag A press dragged away and let go within 2 screen points of where it was pressed was still taken as a drag. A second press dragged out and back drew the circle through three nearly collinear points, or nothing, and a press on the first point drew a circle about 1 pt across. The release distance now decides: such a release keeps the press's point, so a second press draws the circle on the diameter to it, a press on the first point places nothing, and a first press places the first point. The preview and the guides of the drag go with it. --- crates/tools/src/circle.rs | 21 ++++++++++----- crates/tools/src/circle/tests.rs | 46 ++++++++++++++++++++++++++++++++ docs/mcp.md | 1 + 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/crates/tools/src/circle.rs b/crates/tools/src/circle.rs index 9e467b35d6..72f959bad3 100644 --- a/crates/tools/src/circle.rs +++ b/crates/tools/src/circle.rs @@ -8,7 +8,8 @@ //! the release, the tool shows the circle as a dashed outline (solid once it is more than 50,000 //! screen points around) with its points, its center as a small cross, a line from the center to //! each point and, with Measurement Labels on, the diameter by the pointer. The circle is one undo -//! step. Escape, a press dropped part way, and an edit, Undo or Redo made outside the tool drop +//! step. A press let go within 2 screen points of where it was pressed is a click, also after a +//! drag. Escape, a press dropped part way, and an edit, Undo or Redo made outside the tool drop //! the first point. A second press within 3 screen points //! of the first point, or one that snaps to it, is a press on it: let go there (a double-click) it //! places nothing, and dragged out it draws the circle on the diameter it drags out. Where no @@ -137,10 +138,11 @@ impl CircleTool { vec![Action::Exec(c, v)] } - /// Is the press a drag at `ev`: dragged already, or `ev` is [`DRAG_PX`] or more from the press? + /// Is the press let go at `ev` a drag: is `ev` [`DRAG_PX`] or more from the press? A release + /// nearer the press is a click, also after a drag that came back to it. fn drags(&self, cx: &ToolContext, ev: &PointerEvent) -> bool { match self.press { - Some(Press::First { from, dragged, .. } | Press::Second { from, dragged, .. }) => dragged || ev.pos.distance(from) >= cx.tol(DRAG_PX), + Some(Press::First { from, .. } | Press::Second { from, .. }) => ev.pos.distance(from) >= cx.tol(DRAG_PX), None => false, } } @@ -156,9 +158,16 @@ impl Tool for CircleTool { return vec![]; } // A drag ends where it is let go: the release moves the points as a drag to it would. A - // click, or a release within DRAG_PX of the press, keeps the points of the press. - if ev.kind == PointerKind::Up && self.drags(cx, ev) { - self.pointer(cx, &PointerEvent { kind: PointerKind::Drag, ..*ev }); + // click, or a release within DRAG_PX of the press (also after a drag), keeps the points of + // the press. + if ev.kind == PointerKind::Up { + if self.drags(cx, ev) { + self.pointer(cx, &PointerEvent { kind: PointerKind::Drag, ..*ev }); + } else if let Some(Press::First { at, dragged, .. } | Press::Second { at, dragged, .. }) = &mut self.press { + *dragged = false; + self.pointer = Some(*at); + self.snap.clear(); + } } match ev.kind { PointerKind::Move => { diff --git a/crates/tools/src/circle/tests.rs b/crates/tools/src/circle/tests.rs index e262d242ef..5228403670 100644 --- a/crates/tools/src/circle/tests.rs +++ b/crates/tools/src/circle/tests.rs @@ -120,6 +120,52 @@ fn a_drag_ends_where_it_is_let_go() { assert_eq!(t.pointer(&cx, &ev(up, (381.0, 360.0), Mods::default())), circle(&[(300.0, 300.0), (380.0, 360.0)])); } +/// A release within 2 screen points of the press is a click also after a drag that came back to +/// it: a second press draws the circle on the diameter to the press, a press on the first point +/// places nothing, and a first press places the first point. +#[test] +fn a_release_near_the_press_is_a_click_after_a_drag() { + let (d, _) = doc_with_rect(); + let (s, p) = (Selection::default(), paint()); + let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) }; + let mut t = CircleTool::default(); + click(&mut t, &cx, (300.0, 300.0)); + assert_eq!(drag(&mut t, &cx, (380.0, 300.0), &[(300.0, 360.0), (381.0, 300.0)], Mods::default()), circle(&[(300.0, 300.0), (380.0, 300.0)])); + click(&mut t, &cx, (300.0, 300.0)); + assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(300.0, 380.0), (301.0, 300.0)], Mods::default()), vec![]); + assert!(t.ends_on_escape(&cx), "the first point stays"); + assert_eq!(click(&mut t, &cx, (380.0, 360.0)), circle(&[(300.0, 300.0), (380.0, 360.0)])); + assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(380.0, 300.0), (301.0, 300.0)], Mods::default()), vec![]); + assert!(t.ends_on_escape(&cx), "the press placed the first point"); + assert_eq!(click(&mut t, &cx, (380.0, 360.0)), circle(&[(300.0, 300.0), (380.0, 360.0)])); + // Let go near the press straight from far away, the tool shows no circle to the last drag. + t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default())); + t.pointer(&cx, &ev(PointerKind::Drag, (380.0, 300.0), Mods::default())); + assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (301.0, 300.0), Mods::default())), vec![]); + assert_eq!(preview(&t.overlays(&cx)), None); + t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default())); + t.pointer(&cx, &ev(PointerKind::Drag, (300.0, 380.0), Mods::default())); + assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (301.0, 300.0), Mods::default())), vec![]); + assert_eq!(preview(&t.overlays(&cx)), None); + assert!(t.ends_on_escape(&cx)); +} + +/// A press on the first point, dragged to snap to the rectangle's corner anchor and let go near +/// the press, leaves no guides of the drag. +#[test] +fn a_release_near_the_press_hides_the_guides_of_the_drag() { + let (d, _) = doc_with_rect(); + let (s, p) = (Selection::default(), paint()); + let cx = cx(&d, &s, &p); + let mut t = CircleTool::default(); + click(&mut t, &cx, (300.0, 300.0)); + t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default())); + t.pointer(&cx, &ev(PointerKind::Drag, (201.0, 201.0), Mods::default())); + assert!(!t.snap.guides().is_empty(), "the drag snapped to the corner anchor"); + assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (301.0, 300.0), Mods::default())), vec![]); + assert!(t.snap.guides().is_empty(), "{:?}", t.snap.guides()); +} + /// Three points on one line show no circle, and the release draws nothing and starts afresh. A /// circle past the canvas is not shown either. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 5bc273289c..912b371def 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -6706,6 +6706,7 @@ the release, the tool shows the circle as a dashed outline (solid once it is mor with its points, a small cross at its center, a line from the center to each point and, with Measurement Labels on, the diameter by the pointer. Three different points on one line, or a circle past the canvas, show "Circle too large" by the pointer instead, and the release draws nothing. +A press let go within 2 screen points of where it was pressed is a click, also after a drag that came back to it. Escape, a dropped press, and an edit, Undo or Redo made outside the tool drop the first point. A second press within 3 screen points of the first point, or one that snaps to it, is a press on it: let go there (a double-click), it places no second point, and dragged out, it draws the circle on the diameter it drags out. From e886b7ddfdff5e7d5d88af29f321790dded8d9af Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:38:54 -0800 Subject: [PATCH 2/2] Shapes: a Circle tool click near the first point leaves no circle shown A second press within 3 screen points of the first point but not on it, let go where it was pressed, placed nothing but left the pointer at the press, so the tool showed a circle about 2 pt across until the pointer moved. Such a click now puts the pointer back on the first point. --- crates/tools/src/circle.rs | 17 ++++++++++++++--- crates/tools/src/circle/tests.rs | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/tools/src/circle.rs b/crates/tools/src/circle.rs index 72f959bad3..40f52290f4 100644 --- a/crates/tools/src/circle.rs +++ b/crates/tools/src/circle.rs @@ -163,9 +163,20 @@ impl Tool for CircleTool { if ev.kind == PointerKind::Up { if self.drags(cx, ev) { self.pointer(cx, &PointerEvent { kind: PointerKind::Drag, ..*ev }); - } else if let Some(Press::First { at, dragged, .. } | Press::Second { at, dragged, .. }) = &mut self.press { - *dragged = false; - self.pointer = Some(*at); + } else if let Some(press) = &mut self.press { + let (at, on_first) = match press { + Press::First { at, dragged, .. } => { + *dragged = false; + (*at, false) + } + Press::Second { at, on_first, dragged, .. } => { + *dragged = false; + (*at, *on_first) + } + }; + // A click on the first point places nothing: the pointer goes back to that point, so + // the tool shows no circle. + self.pointer = if on_first { self.first } else { Some(at) }; self.snap.clear(); } } diff --git a/crates/tools/src/circle/tests.rs b/crates/tools/src/circle/tests.rs index 5228403670..9d68bdbe27 100644 --- a/crates/tools/src/circle/tests.rs +++ b/crates/tools/src/circle/tests.rs @@ -150,6 +150,23 @@ fn a_release_near_the_press_is_a_click_after_a_drag() { assert!(t.ends_on_escape(&cx)); } +/// A click within 3 screen points of the first point, also one dragged away and let go where it +/// was pressed, places nothing and leaves no circle shown. +#[test] +fn a_click_near_the_first_point_shows_no_circle() { + let (d, _) = doc_with_rect(); + let (s, p) = (Selection::default(), paint()); + let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) }; + let mut t = CircleTool::default(); + click(&mut t, &cx, (300.0, 300.0)); + assert_eq!(drag(&mut t, &cx, (302.0, 300.0), &[(302.0, 380.0), (302.0, 300.0)], Mods::default()), vec![]); + assert_eq!(preview(&t.overlays(&cx)), None); + assert_eq!(click(&mut t, &cx, (302.0, 300.0)), vec![]); + assert_eq!(preview(&t.overlays(&cx)), None); + assert!(t.ends_on_escape(&cx), "the first point stays"); + assert_eq!(click(&mut t, &cx, (380.0, 360.0)), circle(&[(300.0, 300.0), (380.0, 360.0)])); +} + /// A press on the first point, dragged to snap to the rectangle's corner anchor and let go near /// the press, leaves no guides of the drag. #[test]