Scripts: removeAll on a compound path's paths keeps the compound path

pathItems.removeAll() on a compound path deleted the compound path with its last path, which made its handle stale. It now stays, empty, as remove() on its last path leaves it.
This commit is contained in:
dotCooCoo
2026-11-26 00:37:40 -08:00
parent 19e1e51268
commit 3650f71cdc
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -726,7 +726,7 @@ fn art_remove_all(h: &Host, a: &[Data], kind: Kind) -> Answer {
return Err(HostError::Error(format!("{ON_LOCKED_ARTBOARD}: {list}")));
}
if !ids.is_empty() {
on_doc(h, doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})))?;
on_doc(h, doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>(), "keepEmpty": true})))?;
}
Ok(Data::Undefined)
}
+18
View File
@@ -1329,6 +1329,24 @@ fn scoped_remove_all_refuses_art_on_a_locked_artboard() {
assert_eq!(out, vec![json!(0)]);
}
/// `removeAll()` on a compound path's `pathItems` deletes its paths and keeps the compound path,
/// empty, as `remove()` on its last path does.
#[test]
fn removing_all_the_paths_of_a_compound_path_keeps_the_compound_path() {
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("object.compoundPath.make", &json!({})).unwrap();
let compound = layer_order(&s)[0];
let steps = undo_steps(&s);
let out = log(
&mut s,
"var c = app.activeDocument.compoundPathItems[0]; c.pathItems.removeAll(); vc.log([c.typename, c.pathItems.length, app.activeDocument.compoundPathItems.length]);",
);
assert_eq!(out, vec![json!(["CompoundPathItem", 0, 1])]);
assert!(s.active().unwrap().doc.node(compound).is_some_and(|n| n.children().is_some_and(|c| c.is_empty())), "the compound path stays, empty");
assert_eq!(undo_steps(&s), steps + 1);
}
#[test]
fn move_and_duplicate_refuse_art_on_a_locked_artboard() {
let (mut s, a, b) = doc();