mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 21:29:35 +00:00
Scripts: PageItem.remove refuses hidden or locked art as removeAll does
remove() on an object that is hidden or locked, sits in a hidden or locked layer or group, or is a group holding such an object now throws and deletes nothing, the same rule pageItems.removeAll() applies. docs/mcp.md states both rules and that width and height scale along the page's axes.
This commit is contained in:
@@ -1437,8 +1437,14 @@ fn item_z_order_position(h: &Host, a: &[Data]) -> Answer {
|
||||
at.map(|i| num(float(i as u64 + 1))).ok_or_else(|| HostError::Error(STALE_ITEM.into()))
|
||||
}
|
||||
|
||||
/// `remove()`: deletes the object. A hidden or locked object, one in a hidden or locked layer or
|
||||
/// group, or a group holding one is refused, as [`items_remove_all`] refuses it.
|
||||
fn item_remove(h: &Host, a: &[Data]) -> Answer {
|
||||
let item = this_item(h, a)?;
|
||||
let whole = with_doc(h, item.doc, |_, st| editable(&st.doc, item.id) && st.doc.node(item.id).is_some_and(all_editable));
|
||||
if !whole {
|
||||
return Err(HostError::Error(format!("cannot delete hidden or locked objects: {}", item.id.0)));
|
||||
}
|
||||
edit_item(h, item, "edit.clear", &json!({"ids": [item.id.0]}))?;
|
||||
Ok(Data::Undefined)
|
||||
}
|
||||
|
||||
@@ -870,6 +870,31 @@ fn remove_all_refuses_locked_art_before_deleting_anything() {
|
||||
assert_eq!(out, vec![json!(0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_refuses_hidden_or_locked_art_as_remove_all_does() {
|
||||
let (mut s, a, b) = doc();
|
||||
for (on, off) in [
|
||||
(json!({"ids": [b.0], "locked": true}), json!({"ids": [b.0], "locked": false})),
|
||||
(json!({"ids": [b.0], "visible": false}), json!({"ids": [b.0], "visible": true})),
|
||||
] {
|
||||
s.execute("object.setProps", &on).unwrap();
|
||||
let e = failure(&mut s, "app.activeDocument.pageItems[1].remove();");
|
||||
assert!(e.contains(&format!("cannot delete hidden or locked objects: {}", b.0)), "{on}: {e}");
|
||||
assert!(s.active().unwrap().doc.node(b).is_some(), "{on}");
|
||||
s.execute("object.setProps", &off).unwrap();
|
||||
}
|
||||
// A group that holds a locked object is refused too.
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let g = s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap();
|
||||
s.execute("object.setProps", &json!({"ids": [b.0], "locked": true})).unwrap();
|
||||
let e = failure(&mut s, "app.activeDocument.pageItems[0].remove();");
|
||||
assert!(e.contains(&g.to_string()), "{e}");
|
||||
assert!(s.active().unwrap().doc.node(b).is_some());
|
||||
s.execute("object.setProps", &json!({"ids": [b.0], "locked": false})).unwrap();
|
||||
log(&mut s, "app.activeDocument.pageItems[0].remove();");
|
||||
assert!(s.active().unwrap().doc.node(b).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_is_file_open_cannot_probe_outside_script_scope() {
|
||||
let (mut s, _, _) = doc();
|
||||
|
||||
+5
-1
@@ -2665,7 +2665,11 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
for kinds the help pages give no class. Each change runs a command and joins the run's one undo step for each
|
||||
changed document. A value that changes nothing runs no command, and a change to another document leaves the active
|
||||
tab as it was. A bad value throws an error and changes nothing. An object that was deleted, or that a named engine
|
||||
kept from an earlier run, throws `Stale page item`; `index` and `getByName` throw `Not found`; and
|
||||
kept from an earlier run, throws `Stale page item`. `remove()` on an object that is hidden or locked, is inside a
|
||||
hidden or locked layer or group, or is a group that holds one, and `removeAll()` when any object is, throw
|
||||
`cannot delete hidden or locked objects` and delete nothing. Setting `width` or `height` scales the object along
|
||||
the page's axes, so a rotated object then reads back the size that was set. `index` and `getByName` throw
|
||||
`Not found`; and
|
||||
`app.activeDocument` with no document open throws `No active document`. `Document.selection` takes one page item,
|
||||
a list of at most 10,000, `null` or `[]`, and an object that cannot be selected throws `Cannot select` with
|
||||
nothing changed. `getIsFileOpen` compares the path with the open documents' files as text (in a Windows path,
|
||||
|
||||
Reference in New Issue
Block a user