Scripts: pathItems.removeAll() refuses paths on a locked artboard

pathItems.removeAll() deleted paths on a locked artboard, while
pageItems.removeAll() and remove() throw for them. It now throws the
same error and deletes nothing when any path, a path in a group
included, is on a locked artboard.
This commit is contained in:
dotCooCoo
2026-11-25 14:27:30 -08:00
parent 0b155895b2
commit 199c580ca4
3 changed files with 38 additions and 5 deletions
+11 -4
View File
@@ -67,7 +67,7 @@ use vectorcraft_js::{Data, HostClass, HostError, HostItem, HostMember, Realm, Ru
use vectorcraft_tools::params::gradient_params;
use super::{
Answer, Coords, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, coordinate, doc_of, edit_item, editable, find_doc,
Answer, Coords, Doc, Item, Link, NOT_FOUND, ON_LOCKED_ARTBOARD, STALE_ITEM, arg, boolean, class, colors, command, coordinate, doc_of, edit_item, editable, find_doc,
float, frame, get, given, handle_of, id_of, id_parts, item_of, item_rect, later, method, named, num, number, on_doc, pair, point, point_get,
point_method, point_property, property, this_doc, typename_of, whole, with_doc,
};
@@ -340,18 +340,25 @@ fn items_index(h: &super::Host, a: &[Data]) -> Answer {
}
/// `pathItems.removeAll()`: deletes every path of the document in one command. A hidden or locked
/// path, or one in a hidden or locked layer or group, stops it before anything is deleted.
/// path, one in a hidden or locked layer or group, or one on a locked artboard stops it before
/// anything is deleted, as `pageItems.removeAll()` is stopped.
fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
let doc = items_doc(h, a)?;
let (ids, refused) = with_doc(h, doc, |_, st| {
let (ids, refused, on_locked) = with_doc(h, doc, |_, st| {
let ids = path_items(h, st);
let refused: Vec<u64> = ids.iter().filter(|i| !editable(&st.doc, **i)).map(|i| i.0).take(20).collect();
(ids, refused)
let locks = st.doc.locked_artboards();
let on_locked: Vec<u64> = ids.iter().filter(|i| locks.holds_id(**i)).map(|i| i.0).take(20).collect();
(ids, refused, on_locked)
});
if !refused.is_empty() {
let list = refused.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
return Err(HostError::Error(format!("cannot delete hidden or locked paths: {list}")));
}
if !on_locked.is_empty() {
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
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<_>>()})))?;
}
@@ -97,6 +97,31 @@ fn path_items_remove_all_refuses_locked_paths_and_changes_nothing() {
assert_eq!(log(&mut s, "vc.log(app.activeDocument.pathItems.length);"), vec![json!(0)]);
}
/// Paths on a locked artboard stay, a path in a group included: `removeAll()` throws and deletes
/// nothing, as `pageItems.removeAll()` and `remove()` do.
#[test]
fn path_items_remove_all_refuses_paths_on_a_locked_artboard() {
let (mut s, a, b) = doc();
s.execute("object.group", &json!({"ids": [b.0]})).unwrap();
s.execute("select.none", &json!({})).unwrap();
let lock = |s: &mut Session, locked: bool| {
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = locked;
Ok(())
})
.unwrap();
};
lock(&mut s, true);
let (before, steps) = (art(&s), undo_steps(&s));
let e = failure(&mut s, "app.activeDocument.pathItems.removeAll();");
assert!(e.contains("cannot delete objects on a locked artboard") && e.contains(&a.0.to_string()) && e.contains(&b.0.to_string()), "{e}");
assert_eq!(art(&s), before);
assert_eq!(undo_steps(&s), steps);
lock(&mut s, false);
log(&mut s, "app.activeDocument.pathItems.removeAll();");
assert_eq!(log(&mut s, "vc.log(app.activeDocument.pathItems.length);"), vec![json!(0)]);
}
#[test]
fn shape_creators_use_documented_defaults_and_y_up() {
let mut s = Session::new();
+2 -1
View File
@@ -2804,7 +2804,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot
themselves, such as a text frame's `contents`, are not defined yet and read as `undefined`.
- `Document.pathItems` (https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/) lists the document's paths in the
order of `pageItems`, paths inside groups and compound paths included, with `length`, `[i]`, `index(key)`,
`getByName(name)`, `removeAll()`, `add()` (a path with no points, from `path.create`, painted as new art; when new
`getByName(name)`, `removeAll()` (when any path is on a locked artboard, it throws
`cannot delete objects on a locked artboard` and deletes nothing), `add()` (a path with no points, from `path.create`, painted as new art; when new
art has no fill and no stroke, the path has neither), and the shape creators
`rectangle(top, left, width, height, reversed?)`, `roundedRectangle(top, left, width, height, horizontalRadius = 15,
verticalRadius = 20, reversed?)`, `ellipse(top = 100, left = 100, width = 50, height = 100, reversed?, inscribed?)`,