diff --git a/crates/tools/src/builder/live_paint.rs b/crates/tools/src/builder/live_paint.rs index a907a319bb..2ae2f082ee 100644 --- a/crates/tools/src/builder/live_paint.rs +++ b/crates/tools/src/builder/live_paint.rs @@ -456,6 +456,12 @@ impl Tool for LivePaintBucketTool { if self.fill_drag.take().is_some() { vec![Action::Commit] } else { vec![] } } + /// The pointer hovers nothing for the tool: its highlight and its swatch preview go. + fn hover_ended(&mut self, _cx: &ToolContext) { + self.hover = LpHover::None; + self.at = None; + } + fn overlays(&self, cx: &ToolContext) -> Vec { let mut out = lp_overlays(&self.hover, &self.cache, self.color, self.width as f32, (self.width * LP_BUCKET_EDGE_FRACTION) as f32); // No chips during a fill drag, or while Alt makes the tool sample with the eyedropper. diff --git a/crates/tools/src/builder/tests.rs b/crates/tools/src/builder/tests.rs index 07a703be2d..01b64ee8c3 100644 --- a/crates/tools/src/builder/tests.rs +++ b/crates/tools/src/builder/tests.rs @@ -1108,6 +1108,21 @@ fn bucket_swatch_preview_follows_the_release_point() { assert_eq!(chip_x(&t), Some(75.0)); } +/// When the pointer leaves the canvas, the Live Paint Bucket's swatch preview and highlight go. +#[test] +fn bucket_hover_ended_drops_the_swatch_preview_and_highlight() { + let (d, ..) = live_group_doc(); + let s = Selection::default(); + let p = paint(); + let cx = cx(&d, &s, &p); + let mut t = LivePaintBucketTool::default(); + t.pointer(&cx, &ev(PointerKind::Move, 75.0, 25.0)); + let ov = t.overlays(&cx); + assert!(ov.iter().any(|o| matches!(o, Overlay::Swatch { .. })) && ov.iter().any(|o| matches!(o, Overlay::Path { .. })), "{ov:?}"); + t.hover_ended(&cx); + assert!(t.overlays(&cx).is_empty()); +} + #[test] fn bucket_options_choose_what_a_click_paints() { let (d, gid, ..) = live_group_doc();