From f73280731a9f76ebf161ab586a274d069345a45a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 10:07:33 -0800 Subject: [PATCH] Paint: invert and complement of a group remember the fill its proxy shows paint.invert and paint.complement given a group with a fill or stroke of its own remembered the new paint of the first object inside it, while the Fill and Stroke proxies show the group's own paint. The remembered paint now follows the proxy: for each object given, in order, a group whose own fill or stroke changed gives that paint, otherwise the first object inside it that is not graph design art does. --- crates/engine/src/cmd/graph/tests.rs | 5 +++++ crates/engine/src/cmd/paint.rs | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 2ead810dff..ae48718a63 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -635,6 +635,11 @@ fn invert_of_a_group_recolors_its_own_fill_and_leaves_design_art() { assert_ne!(own(&s), own_was, "the group's own fill"); assert_ne!(look(&s, mark), mark_was); assert_eq!(look(&s, art), art_was); + // The color remembered is the group's own new fill, which the Fill proxy shows. + let Some(Paint::Solid { color, .. }) = s.doc().unwrap().doc.node(group).unwrap().proxy_paint_only(false, None).cloned() else { + panic!("the group's fill is not a solid color") + }; + assert_eq!((s.last_solid, s.recent_colors.first().copied()), (color, Some(color))); let (own_was, mark_was) = (own(&s), look(&s, mark)); s.execute("paint.invert", &json!({"ids": [group.0], "target": "contents"})).unwrap(); assert_eq!(own(&s), own_was, "target: contents"); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index c37d6519bd..5ae2ebd4c9 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1156,17 +1156,25 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( .and_then(|n| n.proxy_paint_only(stroke, None)) .cloned() }; - let own_before: Vec> = roots.iter().map(|id| own(d, *id)).collect(); + let own_before: std::collections::HashMap = roots.iter().filter_map(|id| Some((*id, own(d, *id)?))).collect(); let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": roots.iter().map(|i| i.0).collect::>()}); let r = super::colorcmds::recolor_except(s, &q, cmd, label, f, art)?; + // As the proxy shows a group: its own fill or stroke when the edit changed it, else the first object inside it + // that is not design art (which keeps its paint). The first object given that has either shows it. let d = &s.doc()?.doc; - let leaves = super::appearance::drop_design_art(d, leaf_targets(s, &ids)?); - // With only design art inside, which keeps its paint, the first group whose own fill or stroke changed shows it. - let shown_at = leaves - .first() - .copied() - .or_else(|| roots.iter().zip(&own_before).find(|(id, was)| was.is_some() && own(d, **id) != **was).map(|(id, _)| *id)) - .map(|id| (id, None)); + let mut shown_at = None; + for id in &ids { + if let Some(was) = own_before.get(id) + && own(d, *id).as_ref() != Some(was) + { + shown_at = Some((*id, None)); + break; + } + if let Some(leaf) = super::appearance::drop_design_art(d, leaf_targets(s, &[*id])?).first() { + shown_at = Some((*leaf, None)); + break; + } + } (r, shown_at) } };