Artwork Cleanup: Release All Containers keeps objects with live effects and layer masks on locked artboards

- A group or other container with live effects on its appearance, or on its
  fill and stroke rows, stays whole with everything in it.
- A layer keeps clipping when its clipping path alone overlaps a locked artboard.
- A null \ids\ takes the selection, as in every other command that falls back
  to it.
This commit is contained in:
dotCooCoo committed 2026-11-29 22:45:25 -08:00
1 parent 52b52c5524
commit bcdf0b2845
3 files changed
+93 -12

No files matched your search

@@ -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 they clip artwork on 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; defaults apply only to omitted values, and explicit null values are errors} 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 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, 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,12 +66,14 @@ 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, whose contents
/// would lose what it does to them.
/// whose parts would lose their editable corners, or one with an opacity mask or live effects
/// on its appearance or fill and stroke rows.
fn live(n: &Node) -> bool {
let x = n.extras();
matches!(&n.kind, NodeKind::Blend { .. } | NodeKind::Envelope { .. } | NodeKind::Repeat(_) | NodeKind::Intertwine { .. })
|| matches!(&n.kind, NodeKind::Path { live: Some(l), .. } if matches!(**l, LiveShape::Path { .. }))
|| !n.appearance.effects.is_empty()
|| n.appearance.items.iter().any(|item| !item.effects().is_empty())
|| x.mask.is_some()
|| x.shaper.is_some()
|| x.trace.is_some()
@@ -210,7 +212,7 @@ impl Release<'_> {
}
let before = self.total();
let mut clips = n.clips();
if clips && n.is_layer() && self.kinds.clips && !n.children().is_some_and(|children| children.iter().skip(1).any(|c| self.holds_art(c))) {
if clips && n.is_layer() && self.kinds.clips && !n.children().is_some_and(|children| children.iter().any(|c| self.holds_art(c))) {
self.counts[1] += 1;
let n = Arc::make_mut(&mut n);
n.set_clips(false);
@@ -288,7 +290,7 @@ fn release_all(s: &mut Session, p: &Value) -> Result<Value> {
if p.get("scope").is_some_and(|v| !matches!(v.as_str(), Some("selection" | "document"))) {
return Err(bad(COMMAND, "`scope` must be \"selection\" or \"document\""));
}
if let Some(ids) = p.get("ids") {
if let Some(ids) = p.get("ids").filter(|v| !v.is_null()) {
let ids = ids.as_array().ok_or_else(|| bad(COMMAND, "`ids` must be an array of non-negative integer object ids"))?;
let mut seen = HashSet::new();
for id in ids {
@@ -401,6 +401,49 @@ fn release_all_keeps_a_directly_named_descendant_of_a_live_object() {
}
}
#[test]
fn release_all_keeps_appearance_effects_and_directly_targeted_descendants() {
for item in [None, Some(0), Some(1)] {
let mut s = session();
let a = rect(&mut s, 10.0, 10.0);
let b = rect(&mut s, 15.0, 15.0);
let inner = compound(&mut s, &[a, b]);
let c = rect(&mut s, 20.0, 20.0);
select(&mut s, &[inner, c]);
let applied = s.execute("effect.apply", &json!({"effect": "pathfinder.add"})).unwrap();
assert_eq!(applied["grouped"], true);
let live = selected(&s)[0];
assert!(matches!(node(&s, live).unwrap().kind, NodeKind::Group { clip: false, .. }));
assert!(!node(&s, live).unwrap().is_compound_shape());
assert_eq!(node(&s, live).unwrap().appearance.effects[0].id, "pathfinder.add");
if let Some(item) = item {
change(&mut s, live, |n| {
let effects = n.appearance.effects.clone();
*n.appearance = red();
*n.appearance.effects_mut(Some(item)).unwrap() = effects;
});
}
let before = s.doc().unwrap().doc.clone();
let steps = undo_steps(&s);
for (target, params) in [
(live, json!({})),
(live, json!({"scope": "document"})),
(live, json!({"ids": [live.0]})),
(inner, json!({})),
(inner, json!({"ids": [inner.0]})),
] {
select(&mut s, &[target]);
let r = s.execute(C, &params).unwrap();
assert_eq!(counts(&r), (0, 0, 0), "{item:?}: {params}: {r}");
assert!(std::sync::Arc::ptr_eq(&before, &s.doc().unwrap().doc));
assert_eq!(selected(&s), [target]);
assert_eq!(undo_steps(&s), steps);
assert_eq!(s.doc().unwrap().doc.parent_of(inner), Some(live));
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(inner));
}
}
}
#[test]
fn release_all_keeps_a_layer_mask_over_locked_artboard_artwork() {
for named in [false, true] {
@@ -432,6 +475,40 @@ fn release_all_keeps_a_layer_mask_over_locked_artboard_artwork() {
}
}
#[test]
fn release_all_keeps_a_layer_mask_that_alone_overlaps_a_locked_artboard() {
for named in [false, true] {
let mut s = session();
let mask = rect(&mut s, 0.0, 0.0);
let outside = rect(&mut s, 500.0, 10.0);
let g = group(&mut s, &[outside]);
let layer_id = s.doc().unwrap().doc.layers[0].id;
change(&mut s, layer_id, |n| n.set_clips(true));
change(&mut s, mask, |n| {
if let NodeKind::Path { clipping, .. } = &mut n.kind {
*clipping = true;
}
});
select(&mut s, &[]);
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = true;
Ok(())
})
.unwrap();
let original_mask = s.doc().unwrap().doc.node_arc(mask).unwrap().clone();
let steps = undo_steps(&s);
let p = if named { json!({"ids": [layer_id.0]}) } else { json!({"scope": "document"}) };
let r = s.execute(C, &p).unwrap();
assert_eq!(counts(&r), (1, 0, 0), "{p}: {r}");
assert_eq!(undo_steps(&s), steps + 1);
assert!(node(&s, layer_id).unwrap().clips());
assert!(matches!(node(&s, mask).unwrap().kind, NodeKind::Path { clipping: true, .. }));
assert!(std::sync::Arc::ptr_eq(&original_mask, s.doc().unwrap().doc.node_arc(mask).unwrap()));
assert_eq!(layer(&s, 0), [mask, outside]);
assert!(node(&s, g).is_none());
}
}
#[test]
fn release_all_reuses_unchanged_siblings_when_rebuilding_a_layer() {
let mut s = session();
@@ -560,7 +637,7 @@ fn release_all_rejects_null_options_without_editing_artwork() {
select(&mut s, &selection);
let before = s.doc().unwrap().doc.clone();
let steps = undo_steps(&s);
for key in ["ids", "scope", "groups", "clipGroups", "compoundPaths"] {
for key in ["scope", "groups", "clipGroups", "compoundPaths"] {
let mut p = json!({});
p[key] = Value::Null;
let error = s.execute(C, &p).unwrap_err();
+8 -6
View File
@@ -16585,13 +16585,15 @@ locked group becomes locked. Locked and hidden objects stay locked or hidden and
Release All Containers…) takes apart every container at every level of nesting as one undo step, so that only the
objects they held are left. `scope` is `"selection"` or `"document"`; by default it is the selection, or the document
while nothing is selected. `ids` names the objects, groups and layers to release in instead of `scope`; giving both is
an error. Duplicate IDs are an error. Defaults apply only to omitted values; explicit null values are errors.
`groups` ungroups groups, `clipGroups` ungroups clipping groups and makes layers stop clipping unless they
clip artwork on a locked artboard (released clipping paths stay as plain paths), and `compoundPaths` turns compound
paths, and paths of several subpaths, into one path per subpath. Each is true by default, and at least one must be true.
an error. Duplicate IDs are an error. A null `ids` takes the selection as an omitted one does; a null `scope`, `groups`, `clipGroups` or `compoundPaths` is an error.
`groups` ungroups groups, `clipGroups` ungroups clipping groups and makes layers stop clipping unless
their clipping path or clipped artwork overlaps a locked artboard (released clipping paths stay as plain paths), and
`compoundPaths` turns compound paths, and paths of several subpaths, into one path per subpath. Each is true by default,
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 an opacity
mask, compound shapes, Live Paint groups, graphs, dimensions, flares, Objects on Path, generated art, Shaper Groups,
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,
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