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]