From 32afba75ae22ba3c79886042a8edec15d490b2a0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 21:15:40 -0800 Subject: [PATCH] Live Paint: a Cmd-drag cut short keeps the bucket's colors With the Live Paint Bucket active, Cmd lends the Selection tool for a drag. When the bucket was chosen again during a drag of a corner, pie, blend or similar widget, the lent tool canceled the drag as it went back, after the session had already stopped treating the bucket as the lender. With New Art Has Basic Appearance off, the cancel then gave the selected object's appearance to the colors the bucket paints with. The lent tool's last actions now run while the session still counts them as the bucket's, as the Eyedropper's sample for the bucket does. --- crates/engine/src/cmd/paint.rs | 13 +++++++++++-- crates/engine/src/lib.rs | 5 +++-- crates/engine/src/tests/build.rs | 28 ++++++++++++++++++++++++++++ crates/engine/src/tooling.rs | 6 ++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index b94a45e4f5..6666a1d7a3 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -373,16 +373,25 @@ impl DocState { } } +/// Is `t` the Live Paint Bucket, or a tool armed to switch back to it after its pick? +fn works_for_bucket(t: &dyn vectorcraft_tools::Tool) -> bool { + t.id() == LIVE_PAINT_BUCKET || t.returns_to() == Some(LIVE_PAINT_BUCKET) +} + impl Session { + /// Did the Live Paint Bucket, or the Eyedropper armed for it, lend the active tool (a Cmd+click)? + pub(crate) fn lent_by_bucket(&self) -> bool { + self.lender.as_deref().is_some_and(works_for_bucket) + } + /// Do the fill and stroke proxies, and the paint commands that name no objects, stand for the /// colors the Live Paint Bucket paints with? They do while the bucket is the active tool, while /// a Cmd+click with the bucket uses the Selection tool, and while the Eyedropper samples into a /// stop of the bucket's gradient for the Gradient panel's eyedropper, up to and including the /// sample its click takes before it switches back to the bucket. pub fn bucket_paints(&self) -> bool { - let for_bucket = |t: &dyn vectorcraft_tools::Tool| t.id() == LIVE_PAINT_BUCKET || t.returns_to() == Some(LIVE_PAINT_BUCKET); // A Cmd+click lends the Selection tool to the bucket, or to the Eyedropper armed for it. - self.back_to_bucket || for_bucket(self.tool.as_ref()) || self.lender.as_deref().is_some_and(for_bucket) + self.back_to_bucket || works_for_bucket(self.tool.as_ref()) || self.lent_by_bucket() } /// The tool the active tool's armed one-shot pick switches back to after its click diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e2e6430f1e..68067dc697 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -75,8 +75,9 @@ pub struct Session { /// back as it was at the release ([`Session::pointer`]). pub(crate) lender: Option>, /// Set while tool actions that end by switching back to the Live Paint Bucket are applied (the - /// Eyedropper's sample into a stop of the bucket's gradient): their paint commands change the - /// colors the bucket paints with ([`Session::bucket_paints`]). + /// Eyedropper's sample into a stop of the bucket's gradient), and while a tool the bucket lent + /// is deactivated as it goes back: their paint commands change the colors the bucket paints + /// with ([`Session::bucket_paints`]). pub(crate) back_to_bucket: bool, /// Pointer and key input that came while the tool computed an edit on another thread, each with /// its number and view, made in order once the edit is applied. diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index b37550d5c5..32a9db4b21 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -3493,6 +3493,34 @@ fn live_paint_bucket_keeps_its_colors_through_the_stop_eyedropper_and_a_cmd_clic assert_eq!((s.paint.fill.clone(), s.tool_returns_to()), (fill, None), "the pick ended without a sample"); } +/// A Cmd-drag of a corner widget with the Live Paint Bucket that is cut short by choosing the +/// bucket again (the Selection tool it lent cancels the drag as it goes back) leaves the bucket's +/// colors as they were, with New Art Has Basic Appearance off: the selected object's appearance +/// does not replace them. +#[test] +fn live_paint_bucket_keeps_its_colors_when_a_lent_drag_is_cut_short() { + let v = ViewInfo::default(); + let mut s = session(); + let rect = rect(&mut s, 300.0, 300.0, 100.0, 100.0); + s.execute("paint.setFill", &json!({"color": "#00ff00", "ids": [rect.0]})).unwrap(); + s.execute("appearance.setNewArtBasic", &json!({"on": false})).unwrap(); + s.execute("select.set", &json!({"ids": [rect.0]})).unwrap(); + s.select_tool("livePaintBucket", v).unwrap(); + s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap(); + let fill = s.paint.fill.clone(); + let st = s.doc().unwrap(); + let w = vectorcraft_tools::corners::CornerWidgets::showing(&st.doc, &st.selection, v.zoom, false, true, 180.0).expect("corner widgets show"); + let at = w.visible().next().expect("a widget"); + let cmd = Mods { cmd: true, ..Mods::default() }; + s.pointer(&PointerEvent::new(PointerKind::Down, at.x, at.y).with_mods(cmd), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, at.x + 8.0, at.y + 8.0).with_mods(cmd), v).unwrap(); + assert_eq!(s.tool_id(), "selection", "the bucket lent the Selection tool for the drag"); + assert!(s.in_interaction(), "the corner widget drag is in progress"); + s.select_tool("livePaintBucket", v).unwrap(); + assert_eq!(s.tool_id(), "livePaintBucket"); + assert_eq!(s.paint.fill, fill, "the bucket's fill stays"); +} + /// A gradient stop selected on the selection's gradient is not selected once the Live Paint /// Bucket is active (its proxies show the default paint), and one selected on the bucket's /// gradient is not selected once another tool is chosen. diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 7c1af811ed..4323323e22 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -319,6 +319,7 @@ impl Session { /// Pen goes on drawing its path), less the work the gesture ended as a command would: a /// Cmd+click that takes the type being edited out of the selection ends its edit (#3779). pub(crate) fn give_back_tool(&mut self, view: ViewInfo) -> Result<()> { + let lent_by_bucket = self.lent_by_bucket(); let Some(lender) = self.lender.take() else { return Ok(()) }; // The points the lent tool left picked go back to the tool it was lent to when that tool // picks mesh points, none when it unpicked them all (#8090). Group Selection and the @@ -328,7 +329,12 @@ impl Session { .then(|| self.tool.options().get("meshPoints").cloned()) .flatten() .filter(|p| lender.options().get("meshPoints") != Some(p)); + // The lent tool's last actions (a drag it cancels or keeps) still count as the Live Paint + // Bucket's when the bucket lent it ([`Session::bucket_paints`]). + let outer_bucket = self.back_to_bucket; + self.back_to_bucket |= lent_by_bucket; let r = self.deactivate_tool(view); + self.back_to_bucket = outer_bucket; self.keep_tool_settings(); self.tool = lender; if let Some(points) = mesh_points {