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.
This commit is contained in:
dotCooCoo
2026-11-15 10:07:33 -08:00
parent 3e2a2ad9ac
commit f73280731a
2 changed files with 21 additions and 8 deletions
+5
View File
@@ -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");
+16 -8
View File
@@ -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<Option<Paint>> = roots.iter().map(|id| own(d, *id)).collect();
let own_before: std::collections::HashMap<NodeId, Paint> = 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::<Vec<_>>()});
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)
}
};