diff --git a/crates/tools/src/draw2/family.rs b/crates/tools/src/draw2/family.rs index 87c11abba9..a815c02d2a 100644 --- a/crates/tools/src/draw2/family.rs +++ b/crates/tools/src/draw2/family.rs @@ -448,6 +448,10 @@ impl Tool for FamilyTool { _ => self.grid_skew_key(key).is_some(), } } + /// The pointer left the canvas: the Smart Guide of the hover goes. + fn hover_ended(&mut self, _cx: &ToolContext) { + self.snap.clear(); + } fn overlays(&self, cx: &ToolContext) -> Vec { let mut o = self.snap.guides().to_vec(); if let Some(s) = self.start.filter(|_| self.began && cx.measurement_labels) { @@ -1254,6 +1258,23 @@ mod tests { assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "align"))); } + /// The "anchor" label a hover shows goes when the pointer leaves the canvas. + #[test] + fn leaving_the_canvas_drops_the_hover_label() { + let (d, _) = doc_with_rect(); + let s = Selection::default(); + let p = paint(); + let cx = cx(&d, &s, &p); + let label = |o: &[Overlay]| o.iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "anchor")); + for id in ["arc", "spiral", "rectangularGrid", "polarGrid"] { + let mut t = FamilyTool::new(id); + t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 98.0, 102.0)); + assert!(label(&t.overlays(&cx)), "{id}"); + t.hover_ended(&cx); + assert!(!label(&t.overlays(&cx)), "{id}: {:?}", t.overlays(&cx)); + } + } + /// A grid's Default Size and Reference Point are options for a click's dialog; the drag /// draws the box it is dragged to and leaves them out of its command. #[test] diff --git a/crates/tools/src/shape.rs b/crates/tools/src/shape.rs index 7376efd5b0..b93c94dddc 100644 --- a/crates/tools/src/shape.rs +++ b/crates/tools/src/shape.rs @@ -973,9 +973,11 @@ impl Tool for ShapeTool { fn ends_on_escape(&self, _cx: &ToolContext) -> bool { !self.through.is_empty() } - /// The pointer left the canvas: the circle's preview through it goes. + /// The pointer left the canvas: the circle's preview through it and the Smart Guide of the + /// hover go. fn hover_ended(&mut self, _cx: &ToolContext) { self.hover = None; + self.snap.clear(); } /// An edit, Undo or Redo made outside the tool, or another document, drops the points placed /// for a circle. diff --git a/crates/tools/src/shape/tests.rs b/crates/tools/src/shape/tests.rs index 59ae1d8e83..fa089bf4e7 100644 --- a/crates/tools/src/shape/tests.rs +++ b/crates/tools/src/shape/tests.rs @@ -968,6 +968,23 @@ fn corners_snap_to_smart_guides() { assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text == &cx.segment_measure_label(from, to)))); } +/// The "anchor" label a hover shows goes when the pointer leaves the canvas, for every shape tool. +#[test] +fn leaving_the_canvas_drops_the_hover_label() { + let (d, _) = doc_with_rect(); + let s = Selection::default(); + let p = paint(); + let cx = cx(&d, &s, &p); + let label = |o: &[Overlay]| o.iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "anchor")); + for id in ["rectangle", "roundedRectangle", "ellipse", "polygon", "star", "lineSegment"] { + let mut t = ShapeTool::new(id); + t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 98.0, 102.0)); + assert!(label(&t.overlays(&cx)), "{id}"); + t.hover_ended(&cx); + assert!(!label(&t.overlays(&cx)), "{id}: {:?}", t.overlays(&cx)); + } +} + /// Line Segment Tool Options: Length and Angle are options (for a click's dialog), and Fill /// Line makes the drag's line take the current fill. #[test]