Scripts: new paths skip a locked or hidden active layer

Document.pathItems.add() and the shape creators passed the active layer
as onLayer even when it was locked or hidden, so path.create refused it
and the script threw, while textFrames.add() and the app's own creation
commands put the new art on the topmost shown, unlocked layer. The path
creators now choose that layer the same way. While an opacity mask,
pattern or symbol is being edited, they use that edit's layer, and a
locked or hidden editing layer still throws. When every layer is locked
or hidden, the call throws and makes no path.

The creators came in with #9304.
This commit is contained in:
dotCooCoo committed 2026-12-02 23:31:52 -08:00
1 parent 4002b2b66c
commit 7a480a7524
4 files changed
+83 -4

No files matched your search

+15 -2
View File
@@ -373,6 +373,19 @@ fn paint_owner<'a>(d: &'a crate::Document, id: NodeId, n: &'a crate::doc::Node)
d.parent_of(id).and_then(|p| d.node(p)).filter(|p| matches!(p.kind, NodeKind::Compound { .. }) || p.is_compound_shape()).unwrap_or(n)
}
/// A script's new path goes on the active layer while it is shown and unlocked, or the topmost
/// shown, unlocked layer otherwise. While an opacity mask, pattern or symbol is being edited,
/// the path goes on the layer recorded by that edit mode. `create::on_layer` validates the layer.
fn new_path_layer(st: &crate::DocState) -> Option<NodeId> {
let d = &st.doc;
if let Some(layer) =
d.mask_edit.map(|e| e.layer).or_else(|| d.pattern_edit.as_ref().map(|e| e.layer)).or_else(|| d.symbol_edit.as_ref().map(|e| e.layer))
{
return Some(layer);
}
st.current_layer().filter(|l| d.is_editable(*l)).or_else(|| d.default_layer())
}
/// Runs a path creation command with its layer placement recorded.
fn drawing_normally(h: &super::Host, parent: Option<NodeId>, id: &str, params: &Value) -> std::result::Result<(Data, Value), HostError> {
let mut params = params.clone();
@@ -583,7 +596,7 @@ fn made_id(r: &(Data, Value)) -> std::result::Result<NodeId, HostError> {
fn make(h: &super::Host, doc: Doc, id: &str, params: &Value, reversed: bool) -> Answer {
let made = keeping_paint(h, || {
on_doc(h, doc.uid, true, |h| {
let parent = with_doc(h, doc, |_, st| st.current_layer().or_else(|| st.doc.default_layer()));
let parent = with_doc(h, doc, |_, st| new_path_layer(st));
let id = made_id(&drawing_normally(h, parent, id, params)?)?;
if reversed {
command(h, "path.reverse", &json!({"ids": [id.0]}))?;
@@ -749,7 +762,7 @@ fn items_add(h: &super::Host, a: &[Data]) -> Answer {
let ap = h.session.borrow().new_art();
ap.fill_paint().is_none() && ap.stroke_paint().is_none()
};
let parent = with_doc(h, doc, |_, st| st.current_layer().or_else(|| st.doc.default_layer()));
let parent = with_doc(h, doc, |_, st| new_path_layer(st));
let id = made_id(&drawing_normally(h, parent, "path.create", &json!({"d": ""}))?)?;
if unpainted {
command(h, "paint.setStroke", &json!({"none": true, "ids": [id.0], "objectOnly": true}))?;
@@ -680,6 +680,68 @@ fn document_path_creators_use_the_active_layer_during_isolation() {
}
}
/// A locked or hidden active layer does not take a script's new path: the path goes on the
/// topmost shown, unlocked layer, where the app's own creation commands put new art.
#[test]
fn document_path_creators_skip_a_locked_or_hidden_active_layer() {
for (prop, value) in [("locked", true), ("visible", false)] {
for create in ["add()", "rectangle(100, 10, 20, 30)", "roundedRectangle(100, 10, 20, 30)", "ellipse()", "polygon()", "star()"] {
let (mut s, _, _) = doc();
let editable = s.active().unwrap().active_layer.unwrap();
let top = NodeId(s.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap());
assert_eq!(s.active().unwrap().active_layer, Some(top));
s.execute("layer.setProps", &json!({"id": top.0, prop: value})).unwrap();
let before = node(&s, editable).children().unwrap().len();
log(&mut s, &format!("app.activeDocument.pathItems.{create};"));
let st = s.active().unwrap();
assert!(st.doc.node(top).unwrap().children().unwrap().is_empty(), "{prop} {create}");
let children = st.doc.node(editable).unwrap().children().unwrap();
assert_eq!(children.len(), before + 1, "{prop} {create}");
let made = children.last().unwrap();
assert!(matches!(made.kind, NodeKind::Path { .. }), "{prop} {create}");
}
}
}
/// While an opacity mask is being edited, a locked mask layer refuses a script's new path instead
/// of the path going on an ordinary layer outside the mask.
#[test]
fn document_path_creators_refuse_a_locked_mask_editing_layer() {
let (mut s, a, _) = doc();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
s.execute("transparency.makeOpacityMask", &json!({})).unwrap();
let layer = s.active().unwrap().doc.mask_edit.unwrap().layer;
assert_eq!(s.active().unwrap().active_layer, Some(layer));
s.execute("layer.setProps", &json!({"id": layer.0, "locked": true})).unwrap();
let before = art(&s);
let e = failure(&mut s, "app.activeDocument.pathItems.add();");
assert!(e.contains("onLayer must name an editable layer"), "{e}");
assert_eq!(art(&s), before);
}
#[test]
fn document_path_creators_use_the_mask_editing_layer_after_the_active_layer_changes() {
let (mut s, a, _) = doc();
let ordinary = s.active().unwrap().active_layer.unwrap();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
s.execute("transparency.makeOpacityMask", &json!({})).unwrap();
let layer = s.active().unwrap().doc.mask_edit.unwrap().layer;
s.execute("layer.setCurrent", &json!({"id": ordinary.0})).unwrap();
s.execute("layer.setProps", &json!({"id": ordinary.0, "locked": true})).unwrap();
assert_eq!(s.active().unwrap().active_layer, Some(ordinary));
let before = node(&s, layer).children().unwrap().len();
let ordinary_before = node(&s, ordinary).children().unwrap().len();
log(&mut s, "app.activeDocument.pathItems.add();");
let st = s.active().unwrap();
assert_eq!(st.doc.mask_edit.unwrap().layer, layer);
let children = st.doc.node(layer).unwrap().children().unwrap();
assert_eq!(children.len(), before + 1);
assert!(matches!(children.last().unwrap().kind, NodeKind::Path { .. }));
// The mask's art is stored on its object, which stays on the ordinary layer; that layer gains
// no path of its own.
assert_eq!(node(&s, ordinary).children().unwrap().len(), ordinary_before);
}
#[test]
fn paint_writes_refuse_generated_graph_design_paths() {
for (kind, command) in [("column", "graph.column"), ("line", "graph.marker")] {
+5 -1
View File
@@ -3642,7 +3642,11 @@ through `$`:
radius = 50, innerRadius = 20, points = 5, reversed?)`, which run `shape.rectangle`, `path.create`,
`shape.ellipse`, `shape.polygon` and `shape.star` (and `path.reverse` for `reversed`) and paint the new path as new
art is painted. `add()` and the shape creators put the new path on top of the active layer whatever the drawing
mode, which stays as it was. These creation commands take `onLayer: layerId` to draw normally on that layer and
mode, which stays as it was. For ordinary layer placement, when the active layer is locked or hidden, the new
path goes on the topmost shown, unlocked layer. While an opacity mask, pattern or symbol is being edited, the
new path goes on that editing layer, and the call throws and makes no path when that layer is locked or hidden.
The call also throws and makes no path when the document has layers and every one is locked or hidden.
These creation commands take `onLayer: layerId` to draw normally on that layer and
record this placement for replay. A null `onLayer` draws normally on the active layer.
A `PathItem` (https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/) adds to the page item
members `pathPoints`, `closed`, `evenodd`, `area` (negative for a path that runs counterclockwise), `length`,
+1 -1
View File
@@ -1116,7 +1116,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`.
- Scripts: a page item's `translate`, `rotate`, `resize` and `transform` move, turn, scale and transform the object by offsets, an angle, percentages or a `Matrix` record, about its center or a `Transformation` point, with positions, patterns, gradients and line widths following their arguments (https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/). Each call that moves or reshapes the object runs `object.transform` inside the run's transaction, a call that changes only a path's stroke weight runs `stroke.set`, and a call that changes nothing runs no command. `resize` and `transform` on a member of a compound path with `changeLineWidths` at their own scale set the compound's stroke weight; locked art, art on a locked artboard and bad arguments throw an error with nothing changed (`docs/mcp.md`). `crates/engine/src/tests/script_dom_transform.rs`.
- Scripts: `app.preferences` reads, stores and removes values by key with the type they were set as, keeps them across runs and restarts, and turns the warning before a picked script on with the key `ShowExternalJSXWarning`, and off only after the person answers Yes to a confirm (https://ai-scripting.docsforadobe.dev/jsobjref/Preferences/; the confirm is VectorCraft's own rule); `app` makes, joins, inverts and compares `Matrix` records (https://ai-scripting.docsforadobe.dev/jsobjref/Matrix/), rounding each joined value once from its exact sum of products and deciding whether an inverted value overflows from its exact quotient, and runs Copy, Cut and Paste on the active document inside the run's transaction (https://ai-scripting.docsforadobe.dev/jsobjref/Application/). `crates/engine/src/tests/script_dom_prefs.rs`.
- Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). `pathItems["name"]` reads a path by name as `pageItems` does, and `removeAll()` deletes nothing and throws when any path is hidden or locked or is on a locked artboard. A path takes the page item transforms, and `resize` also sets its stroke weight to a `changeLineWidths` percent from 0 to 100000 (at most 1000 points; a member of a compound sets the compound's stroke); gradients move with positions, so a `changeFillGradients` different from `changePositions` throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`.
- Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). For ordinary layer placement, the creators use the topmost shown, unlocked layer when the active layer is locked or hidden. `pathItems["name"]` reads a path by name as `pageItems` does, and `removeAll()` deletes nothing and throws when any path is hidden or locked or is on a locked artboard. A path takes the page item transforms, and `resize` also sets its stroke weight to a `changeLineWidths` percent from 0 to 100000 (at most 1000 points; a member of a compound sets the compound's stroke); gradients move with positions, so a `changeFillGradients` different from `changePositions` throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`.
- Scripts: `Document.placedItems` and `Document.rasterItems` list a document's linked and embedded images; `placedItems.add()` with a `File` assigned to `file` places an image linked, and `PlacedItem.relink(file)` and `embed()` relink and embed it, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItem/, https://ai-scripting.docsforadobe.dev/jsobjref/RasterItems/ and https://ai-scripting.docsforadobe.dev/jsobjref/RasterItem/ describe them. A raster item's bits per channel, channels, color space and transparency come from its encoded pixels' header. Only files the script may read, of at most 256 MiB and holding an image, are placed or relinked. Rasterizing and capturing are not there yet. `crates/engine/src/tests/script_dom_images.rs`.
- Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, except that the view options (`viewRaster` and `viewVector`) only change the view, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. The source image of a traced item is left out of `pageItems`, `placedItems` and `rasterItems`; a script reaches it through `PluginItem.tracing.sourceArt`. Renaming an ordinary group that holds an image first to `Image Trace`, or moving or duplicating an image to the bottom of an ordinary group with that name, throws an error. `crates/engine/src/tests/script_dom_tracing.rs`.
- Scripts: a document's `default*` members (https://ai-scripting.docsforadobe.dev/jsobjref/Document/) read and set the fill, stroke and stroke options of the next object drawn through `appearance.setNewArt`, leaving the selection and its art as they were, and `scaleFactor` reads 1 (`docs/mcp.md`). `crates/engine/src/tests/script_dom_defaults.rs`.