From f9bd4ca5cd371f0566dfc2ff0f15e35f582b3bfd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 11:43:01 -0800 Subject: [PATCH] Live Paint: contents edits of a group with only source paths keep new art, the reversed pick skips an empty group, and a source group is not its own target A contents edit of a Live Paint group that holds only hidden source paths counted as an empty selection and changed the settings for new art. The reversed Eyedropper now tries each selected object in order, so an empty group passes to the next group and the whole group is sampled. A pick whose source is a Live Paint group no longer paints that group's own faces and edges. --- crates/engine/src/cmd/appearance.rs | 34 ++++++++++++---- crates/engine/src/tests/build.rs | 61 +++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 528c6a9e58..b33af177bb 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -300,7 +300,8 @@ impl ItemTarget { }; let before = ids.len(); ids.retain(|id| !skipped.contains(id)); - let skipped_any = ids.len() != before; + // A contents edit already leaves hidden source paths out of `ids`, so `skipped` is checked on its own too. + let skipped_any = ids.len() != before || !skipped.is_empty(); Ok((ids, skipped_any)) } @@ -1815,13 +1816,23 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { // Reversed, the first selected object's attributes go onto the clicked object; with nothing // selected, what the Eyedropper picked up last does (#4382). let (source, mut targets) = if reverse { - // A Live Paint group selected first is picked up as a whole ([`live_paint_look`]); its hidden source paths are - // not what it draws. + // The selected objects are tried in order: a Live Paint group with a look is picked up as a whole + // ([`live_paint_look`]), any other object gives its first painted leaf, and a group with nothing to pick + // up (its hidden source paths are not what it draws) passes to the next object. let d = &s.doc()?.doc; - let group = selected.first().copied().filter(|id| d.node(*id).and_then(live_paint_look).is_some()); - let (_, _, hidden) = super::paint::live_paint_split(d, &selected); - let first = leaf_targets(s, &selected)?.into_iter().find(|id| !hidden.contains(id)); - let source = match group.or(first) { + let mut first = None; + for root in &selected { + if d.node(*root).and_then(live_paint_look).is_some() { + first = Some(*root); + break; + } + let (_, _, hidden) = super::paint::live_paint_split(d, &[*root]); + if let Some(leaf) = leaf_targets(s, &[*root])?.into_iter().find(|id| !hidden.contains(id)) { + first = Some(leaf); + break; + } + } + let source = match first { Some(first) => Some(first), None if s.eyedropper_sample.is_some() => None, None => return Err(bad(C, "select the object to copy from")), @@ -1855,7 +1866,14 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { }; // A pick of the whole appearance gives a face every fill row and an edge every stroke row. let whole = attrs.appearance.fill == FillAttrs::ALL && attrs.appearance.stroke == StrokeAttrs::ALL; - targets.retain(|id| Some(*id) != source && !hidden.contains(id)); + // A source that is a Live Paint group is not one of its own targets: neither are its faces and edges. + let mut inside_source = HashSet::new(); + if let Some(n) = source.and_then(|id| s.doc().ok()?.doc.node(id)).filter(|n| is_live_paint(n)) { + n.walk(&mut |c| { + inside_source.insert(c.id); + }); + } + targets.retain(|id| Some(*id) != source && !hidden.contains(id) && !inside_source.contains(id)); let mut targets = without_design_art(&s.doc()?.doc, targets, C)?; let node = match source { Some(id) => { diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index 1d67dbdffa..f7c410800a 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -4425,6 +4425,67 @@ fn live_paint_group_eyedropper_picks_up_the_group_and_appends_without_effects() assert!(faces1.iter().zip(&faces0).all(|(f, f0)| f.items.len() > f0.items.len()), "every face takes the fill"); } +/// Reversed onto a clicked object, an empty Live Paint group first in the selection passes to the next +/// selected Live Paint group, whose faces' fill and edges' stroke are both picked up. +#[test] +fn live_paint_group_eyedropper_reversed_skips_an_empty_group_for_the_next_whole_group() { + let mut s = session(); + let g = live(&mut s); + s.execute("select.set", &json!({"ids": [g.0]})).unwrap(); + s.execute("paint.setFill", &json!({"color": "#ff00ff"})).unwrap(); + s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap(); + s.execute("stroke.set", &json!({"weight": 5})).unwrap(); + let empty = rect(&mut s, 600.0, 0.0, 50.0, 50.0); + s.execute("select.set", &json!({"ids": [empty.0]})).unwrap(); + let e = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap()); + let en = node(&s, e); + let parts: Vec = + vectorcraft_tools::builder::faces(&en).iter().chain(vectorcraft_tools::builder::edges(&en).iter()).map(|p| p.id).collect(); + s.edit("t", |d, _| { + d.node_mut(e).unwrap().children_mut().unwrap().retain(|c| !parts.contains(&c.id)); + Ok(()) + }) + .unwrap(); + let target = rect(&mut s, 400.0, 0.0, 50.0, 50.0); + s.execute("appearance.copyFrom", &json!({"source": target.0, "reverse": true, "ids": [e.0, g.0]})).unwrap(); + let a = (*node(&s, target).appearance).clone(); + assert_eq!(a.fill_paint(), Paint::solid(Color::from_hex("#ff00ff").unwrap()), "the faces' fill"); + assert_eq!((a.stroke_paint(), a.stroke_width()), (Paint::solid(Color::from_hex("#0000ff").unwrap()), 5.0), "the edges' stroke"); +} + +/// An Eyedropper pick whose source is the selected Live Paint group leaves the group's own faces and +/// edges as they are. +#[test] +fn live_paint_group_eyedropper_does_not_target_its_own_source_group() { + let mut s = session(); + let g = live(&mut s); + s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "color": "#ff0000"})).unwrap(); + s.execute("livePaint.fill", &json!({"group": g.0, "point": [75, 50], "color": "#00ff00"})).unwrap(); + let before = part_looks(&s, g); + s.execute("select.set", &json!({"ids": [g.0]})).unwrap(); + s.execute("appearance.copyFrom", &json!({"source": g.0})).unwrap(); + assert_eq!(part_looks(&s, g), before); +} + +/// A Live Paint group left with only its hidden source paths is still a selection: a stroke edit of its +/// contents changes nothing and leaves the settings for new art as they are. +#[test] +fn live_paint_group_with_only_source_paths_leaves_new_art_alone_for_a_contents_edit() { + let mut s = session(); + let g = live(&mut s); + let n = node(&s, g); + let parts: Vec = vectorcraft_tools::builder::faces(&n).iter().chain(vectorcraft_tools::builder::edges(&n).iter()).map(|p| p.id).collect(); + s.edit("t", |d, _| { + d.children_mut(Some(g)).unwrap().retain(|c| !parts.contains(&c.id)); + Ok(()) + }) + .unwrap(); + s.execute("select.set", &json!({"ids": [g.0]})).unwrap(); + let (paint0, stroke0) = (s.paint.clone(), s.new_art_stroke()); + s.execute("stroke.setAdvanced", &json!({"target": "contents", "item": 0, "arrowScale": [200, 150]})).unwrap(); + assert_eq!((s.paint.clone(), s.new_art_stroke()), (paint0, stroke0), "new art keeps its stroke"); +} + /// A selected Live Paint group with no part of the edited kind is still a selection: a stroke edit /// of a group without edges, or a fill gradient edit of a group without faces, changes nothing and /// leaves the settings for new art as they are.