Artwork Cleanup: Release All Containers keeps group paint and clipped art on locked artboards

- A group with fill or stroke rows of its own stays whole, so its members
  keep the paint the group draws for them.
- A clipping group whose shown clipped artwork overlaps a locked artboard
  stays whole even when its clipping path lies off the artboard, including
  when a target inside it is named by `ids`. Hidden artwork, art in pattern
  editing mode and runs with `clipGroups` false do not count.
This commit is contained in:
dotCooCoo committed 2026-12-04 17:45:02 -08:00
1 parent 88aef2b8f3
commit ec78385f8c
4 files changed
+215 -8

No files matched your search

@@ -9,7 +9,7 @@ use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use serde_json::{Value, json};
use vectorcraft_doc::{Document, LiveShape, Node, NodeId, NodeKind};
use vectorcraft_doc::{Document, LiveShape, LockedArtboards, Node, NodeId, NodeKind};
use vectorcraft_geom::PathData;
use vectorcraft_tools::builder::is_live_paint;
@@ -27,7 +27,7 @@ pub(super) fn specs() -> Vec<CommandSpec> {
"Release All Containers…",
["Object", "Plug-ins", "Artwork Cleanup"],
None,
"{scope?: \"selection\"|\"document\" (default: the selection, or the document while nothing is selected), ids?: [id…] (the objects, groups and layers to release in, instead of `scope`; duplicate ids are an error), groups?: bool (true: groups are ungrouped), clipGroups?: bool (true: clipping groups are ungrouped and layers stop clipping unless their clipping path or clipped artwork overlaps a locked artboard, their released clipping paths kept as plain paths), compoundPaths?: bool (true: compound paths, and paths of several subpaths, become one path per subpath); at least one of the three true; `scope` and the three are never null} take apart every container of the kinds asked for, at every level of nesting, as one undo step when one goes; layers stay; each object keeps the opacity of the groups and compound paths it was in, and a compound path's paths take its paint; objects with live effects on their appearance or fill and stroke rows, objects with an opacity mask, compound shapes, Live Paint groups, graphs, dimensions, flares, Objects on Path, generated art, Shaper Groups, Image Trace objects, paths with Live Corners, blends, envelopes, repeats, intertwines and other live objects stay whole, including directly selected or named descendants; the entire clipping mask subtree of a clipping group or layer that stays is left as it is, including directly selected or named descendants; from the selection or the document, locked and hidden objects, and objects on a locked artboard, stay whole; named by `ids`, locked and hidden ones are taken apart too (their objects become locked or hidden as they were), but not those on a locked artboard; the selection keeps what it held, each object taken apart replaced by what it left, locked and hidden objects left out → {scope (\"selection\", \"document\" or \"ids\"), ids (the objects selected), groups, clipGroups, compoundPaths (how many of each were released)}",
"{scope?: \"selection\"|\"document\" (default: the selection, or the document while nothing is selected), ids?: [id…] (the objects, groups and layers to release in, instead of `scope`; duplicate ids are an error), groups?: bool (true: groups are ungrouped), clipGroups?: bool (true: clipping groups are ungrouped and layers stop clipping unless their clipping path or clipped artwork overlaps a locked artboard, their released clipping paths kept as plain paths), compoundPaths?: bool (true: compound paths, and paths of several subpaths, become one path per subpath); at least one of the three true; `scope` and the three are never null} take apart every container of the kinds asked for, at every level of nesting, as one undo step when one goes; layers stay; each object keeps the opacity of the groups and compound paths it was in, and a compound path's paths take its paint; objects with live effects on their appearance or fill and stroke rows, groups with fill or stroke rows of their own, objects with an opacity mask, compound shapes, Live Paint groups, graphs, dimensions, flares, Objects on Path, generated art, Shaper Groups, Image Trace objects, paths with Live Corners, blends, envelopes, repeats, intertwines and other live objects stay whole, including directly selected or named descendants; the entire clipping mask subtree of a clipping group or layer that stays is left as it is, including directly selected or named descendants; from the selection or the document, locked and hidden objects, and objects on a locked artboard, stay whole; named by `ids`, locked and hidden ones are taken apart too (their objects become locked or hidden as they were), but not those on a locked artboard; the selection keeps what it held, each object taken apart replaced by what it left, locked and hidden objects left out → {scope (\"selection\", \"document\" or \"ids\"), ids (the objects selected), groups, clipGroups, compoundPaths (how many of each were released)}",
has_doc,
release_all
)]
@@ -66,8 +66,8 @@ struct Release<'a> {
/// Whether `n` stays whole whatever is asked: a live object kept as a group or compound path
/// (a compound shape, Live Paint group, graph, dimension, flare, Objects on Path, generated art,
/// Shaper Group, Image Trace object, a clipping path's painted pieces), a path with Live Corners,
/// whose parts would lose their editable corners, or one with an opacity mask or live effects
/// on its appearance or fill and stroke rows.
/// whose parts would lose their editable corners, one with an opacity mask or live effects
/// on its appearance or fill and stroke rows, or a group with fill or stroke rows of its own.
fn live(n: &Node) -> bool {
let x = n.extras();
matches!(&n.kind, NodeKind::Blend { .. } | NodeKind::Envelope { .. } | NodeKind::Repeat(_) | NodeKind::Intertwine { .. })
@@ -84,6 +84,7 @@ fn live(n: &Node) -> bool {
|| x.generated.is_some()
|| x.live_paint_gaps.is_some()
|| x.clip_pieces
|| (matches!(&n.kind, NodeKind::Group { .. }) && !n.appearance.items.is_empty())
|| n.is_compound_shape()
|| is_live_paint(n)
}
@@ -269,6 +270,18 @@ impl Release<'_> {
}
}
/// Whether shown artwork in `n` overlaps a locked artboard: a plain group that is not live
/// ([`live`]) by its shown members, anything else by its own bounds.
fn shows_on(locks: &LockedArtboards<'_>, n: &Node) -> bool {
if !n.visible {
return false;
}
match (&n.kind, n.children()) {
(NodeKind::Group { clip: false, .. }, Some(children)) if !live(n) => children.iter().any(|c| shows_on(locks, c)),
_ => locks.holds(n),
}
}
/// Whether `id` is in the clipping mask subtree of a clipping group or layer.
fn in_clipping_mask(d: &Document, id: NodeId) -> bool {
d.ancestry(id).is_some_and(|chain| {
@@ -334,7 +347,29 @@ fn release_all(s: &mut Session, p: &Value) -> Result<Value> {
candidates(n, kinds.clips, &mut found);
}
let locks = d.locked_artboards();
found.into_iter().filter(|id| locks.holds_id(*id)).collect()
let mut held: HashSet<NodeId> = found.iter().copied().filter(|id| locks.holds_id(*id)).collect();
// A shown clipping group whose clipped artwork overlaps a locked artboard stays whole,
// wherever its clipping path lies, when clipping groups are released; the clipping groups
// the targets are in count too.
let ancestors = roots.iter().filter_map(|id| d.ancestry(*id)).flatten();
let clip_groups: HashSet<NodeId> = found
.iter()
.copied()
.chain(ancestors)
.filter(|id| kinds.clips && d.node(*id).is_some_and(|n| matches!(&n.kind, NodeKind::Group { clip: true, .. })))
.collect();
// Pattern editing mode's art is on no artboard.
let pattern_layer = d.pattern_edit.as_ref().map(|e| e.layer);
for id in clip_groups {
let shown = d.ancestry(id).is_some_and(|chain| chain.iter().all(|a| Some(*a) != pattern_layer && d.node(*a).is_some_and(|n| n.visible)));
if shown
&& let Some(n) = d.node(id)
&& n.children().is_some_and(|c| c.iter().skip(1).any(|c| shows_on(&locks, c)))
{
held.insert(id);
}
}
held
} else {
HashSet::new()
};
@@ -509,6 +509,177 @@ fn release_all_keeps_a_layer_mask_that_alone_overlaps_a_locked_artboard() {
}
}
#[test]
fn release_all_keeps_a_clipping_group_whose_clipped_art_overlaps_a_locked_artboard() {
let mut s = session();
let art = rect(&mut s, 10.0, 10.0);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[art, mask]);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"scope": "document"})).unwrap();
assert_eq!(counts(&r), (0, 0, 0), "{r}");
assert_eq!(s.doc().unwrap().doc.parent_of(art), Some(g));
assert!(node(&s, g).unwrap().clips());
}
#[test]
fn release_all_keeps_a_named_group_in_a_clipping_group_over_a_locked_artboard() {
let mut s = session();
let art = rect(&mut s, 10.0, 10.0);
let other = rect(&mut s, 40.0, 10.0);
let inner = group(&mut s, &[art, other]);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[inner, mask]);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"ids": [inner.0]})).unwrap();
assert_eq!(counts(&r), (0, 0, 0), "{r}");
assert_eq!(s.doc().unwrap().doc.parent_of(art), Some(inner));
assert_eq!(s.doc().unwrap().doc.parent_of(inner), Some(g));
}
#[test]
fn release_all_takes_apart_a_named_hidden_clipping_group_with_visible_art() {
let mut s = session();
let art = rect(&mut s, 10.0, 10.0);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[art, mask]);
change(&mut s, g, |n| n.visible = false);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"ids": [g.0]})).unwrap();
assert_eq!(counts(&r), (0, 1, 0), "{r}");
assert!(node(&s, g).is_none());
assert!(!node(&s, art).unwrap().visible);
}
#[test]
fn release_all_takes_apart_a_clipping_group_in_a_named_hidden_group() {
let mut s = session();
let art = rect(&mut s, 10.0, 10.0);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[art, mask]);
let other = rect(&mut s, 40.0, 10.0);
let outer = group(&mut s, &[g, other]);
change(&mut s, outer, |n| n.visible = false);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"ids": [outer.0]})).unwrap();
assert_eq!(counts(&r), (1, 1, 0), "{r}");
assert!(node(&s, g).is_none());
}
#[test]
fn release_all_ignores_hidden_clipped_art_over_a_locked_artboard() {
let mut s = session();
let hidden = rect(&mut s, 10.0, 10.0);
let shown = rect(&mut s, 600.0, 10.0);
let inner = group(&mut s, &[hidden, shown]);
change(&mut s, hidden, |n| n.visible = false);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[inner, mask]);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"scope": "document"})).unwrap();
assert_eq!(counts(&r), (1, 1, 0), "{r}");
assert!(node(&s, g).is_none());
assert!(!node(&s, hidden).unwrap().visible);
}
#[test]
fn release_all_keeps_a_clipping_group_whose_group_stroke_reaches_a_locked_artboard() {
let mut s = session();
let a = rect(&mut s, 600.0, 10.0);
let b = rect(&mut s, 640.0, 10.0);
let inner = group(&mut s, &[a, b]);
change(&mut s, inner, |n| n.appearance = Appearance::basic(Paint::None, Paint::solid(Color::rgb(0.0, 0.0, 0.0)), 500.0).into());
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[inner, mask]);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"scope": "document"})).unwrap();
assert_eq!(counts(&r), (0, 0, 0), "{r}");
assert_eq!(s.doc().unwrap().doc.parent_of(inner), Some(g));
}
#[test]
fn release_all_ungroups_off_artboard_groups_in_a_kept_clipping_group() {
let mut s = session();
let a = rect(&mut s, 600.0, 10.0);
let b = rect(&mut s, 640.0, 10.0);
let inner = group(&mut s, &[a, b]);
let on = rect(&mut s, 10.0, 10.0);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[inner, on, mask]);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"scope": "document", "clipGroups": false})).unwrap();
assert_eq!(counts(&r), (1, 0, 0), "{r}");
assert!(node(&s, inner).is_none());
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g));
}
#[test]
fn release_all_takes_apart_pattern_editing_art_over_a_locked_artboard() {
let mut s = session();
let art = rect(&mut s, 10.0, 10.0);
let mask = rect(&mut s, 500.0, 10.0);
let g = clip_group(&mut s, &[art, mask]);
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
let layer = d.layers[0].id;
d.pattern_edit = Some(vectorcraft_doc::PatternEdit { pattern: "Checks".into(), layer, original: None });
Ok(())
})
.unwrap();
let r = s.execute(C, &json!({"scope": "document"})).unwrap();
assert_eq!(counts(&r), (0, 1, 0), "{r}");
assert!(node(&s, g).is_none());
}
#[test]
fn release_all_keeps_a_group_with_its_own_fill_or_stroke() {
let mut s = session();
let a = rect(&mut s, 10.0, 10.0);
let b = rect(&mut s, 40.0, 10.0);
let g = group(&mut s, &[a, b]);
change(&mut s, g, |n| n.appearance = red().into());
let r = s.execute(C, &json!({"scope": "document"})).unwrap();
assert_eq!(counts(&r), (0, 0, 0), "{r}");
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g));
assert_eq!(*node(&s, g).unwrap().appearance, red());
}
#[test]
fn release_all_reuses_unchanged_siblings_when_rebuilding_a_layer() {
let mut s = session();
+1 -1
View File
@@ -17442,7 +17442,7 @@ their clipping path or clipped artwork overlaps a locked artboard (released clip
and at least one must be true.
Layers stay. Objects keep the opacity of
the groups and compound paths they were in, and the paths of a compound path take its paint. Objects with live effects
on their appearance or fill and stroke rows, objects with an opacity mask, compound shapes, Live Paint groups, graphs,
on their appearance or fill and stroke rows, groups with fill or stroke rows of their own, objects with an opacity mask, compound shapes, Live Paint groups, graphs,
dimensions, flares, Objects on Path, generated art, Shaper Groups,
Image Trace objects, paths with Live Corners, blends, envelopes, repeats, intertwines and other live objects stay whole,
including directly selected or named descendants. The entire clipping mask subtree of a clipping group or layer that
+3 -2
View File
@@ -3021,8 +3021,9 @@ state. Tests: `simplify_named_locked_and_hidden_paths`, `deep_ungroup_named_lock
Release All Containers… (`addon.cleanup.releaseAll`) takes apart the groups, clipping groups and compound paths of the
kinds asked for in the selection, the objects named or the whole document, at every level of nesting, as one undo step;
layers stay, and stop clipping when clipping groups are released; paths of several subpaths split into one path per
subpath. Objects with an opacity mask, live objects and paths with Live Corners stay whole. Its dialog previews on the canvas and picks
layers stay, and stop clipping when clipping groups are released unless their clipping path or clipped artwork overlaps
a locked artboard; paths of several subpaths split into one path per subpath. Objects with an opacity mask, groups with
fill or stroke rows of their own, live objects, paths with Live Corners and artwork on a locked artboard stay whole. Its dialog previews on the canvas and picks
where to release and which kinds (VectorCraft's own tool). Tests: `cmd::addons::cleanup::release::tests` in
`vectorcraft-engine` and `addons::cleanup::release::tests` in `vectorcraft-ui-egui`.