Scripts: path points of other Global Edit members go stale when Global Edit changes them

While Global Edit is on, an object model edit of one member (or a move
of a group that holds it) is given to the other members, but the check
that marks read PathPoint handles stale only looked at the edited
object's own subtree. A script that read a point of another member kept
a valid handle after the edit, even when an undo then put the member
back. The check now also looks at each Global Edit member, or the
outermost Objects on Path group that holds it, and skips subtrees the
command left as they were. The stale-point check came in with #9288.

Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo committed 2026-12-02 22:34:57 -08:00
1 parent 4002b2b66c
commit ced550ebef
4 files changed
+88 -9

No files matched your search

+19 -7
View File
@@ -1375,7 +1375,8 @@ fn see_points(h: &super::Host, key: (u64, u64), own: impl FnOnce() -> bool) {
/// [`see_points`] for each path whose points the run has read, after each command, so that a
/// change that a later command reverses still makes the points stale. Paths under the object that
/// the object model is changing ([`super::State`]), or that object itself, take the change as the
/// object model's own, and their points stay valid. A document that is the one the run last looked
/// object model's own, and their points stay valid; the other Global Edit members, which take the
/// object model's edit too, are looked at as well. A document that is the one the run last looked
/// at is skipped, as are its paths.
pub(super) fn see_all_points(h: &super::Host) {
let keys: Vec<(u64, u64)> = {
@@ -1384,18 +1385,27 @@ pub(super) fn see_all_points(h: &super::Host) {
let seen = h.dom.point_nodes.borrow();
let mut keys = Vec::new();
docs.retain(|uid, before| {
let after = s.documents().iter().find(|d| d.uid == *uid).map(|st| &st.doc);
let state = s.documents().iter().find(|d| d.uid == *uid);
let after = state.map(|st| &st.doc);
if after.is_some_and(|after| Arc::ptr_eq(before, after)) {
return true;
}
// Editing a path in an Objects on Path group can move the other paths in the group, so
// the outermost such group is looked at in place of the path.
// the outermost such group is looked at in place of the path. While Global Edit is on,
// an edit of the selected member (also one made by moving a group that holds it) is
// given to the other members, so each of them, or the outermost Objects on Path group
// holding it, is looked at too. Subtrees the command left as they were are skipped.
let mut todo: Vec<_> = match h.dom.editing.get().filter(|item| item.doc.uid == *uid) {
Some(item) => {
let group = before
.ancestry(item.id)
.and_then(|a| a.into_iter().find(|g| before.node(*g).is_some_and(vectorcraft_doc::objects_on_path::is_objects_on_path)));
node_arc(before, group.unwrap_or(item.id)).into_iter().collect()
let root = |id: NodeId| {
before
.ancestry(id)
.and_then(|a| a.into_iter().find(|g| before.node(*g).is_some_and(vectorcraft_doc::objects_on_path::is_objects_on_path)))
.unwrap_or(id)
};
let members = state.and_then(|st| st.global_edit.as_ref()).map(|ge| ge.members.iter().map(|(id, _)| *id)).into_iter().flatten();
let mut roots = std::collections::HashSet::new();
std::iter::once(item.id).chain(members).map(root).filter(|id| roots.insert(*id)).filter_map(|id| node_arc(before, id)).collect()
}
None => before.layers.iter().collect(),
};
@@ -1417,6 +1427,8 @@ pub(super) fn see_all_points(h: &super::Host) {
false
}
});
keys.sort_unstable();
keys.dedup();
keys
};
let editing = h.dom.editing.get();
@@ -1588,6 +1588,71 @@ fn a_point_outside_an_inner_objects_on_path_group_is_stale_after_its_path_change
assert_eq!(art(&s), before);
}
/// Global Edit gives an edit of one member to the others, so a point read of another member before
/// the edit is stale afterwards, even when an undo puts the member back.
#[test]
fn a_point_of_another_global_edit_member_is_stale_after_an_edit_and_undo() {
let (mut s, a, _) = doc();
let c = rect(&mut s, 200.0, 100.0, 30.0, 40.0);
s.execute("object.setProps", &json!({"ids": [a.0], "name": "edit"})).unwrap();
s.execute("object.setProps", &json!({"ids": [c.0], "name": "m"})).unwrap();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let r = s.execute("select.globalEdit", &json!({})).unwrap();
assert_eq!(r["count"], json!(2), "{r}");
let before = art(&s);
let out = log(
&mut s,
"var P = app.activeDocument.pathItems, p = P.getByName('edit'), m = P.getByName('m');\
vc.log(m.pathPoints[0].anchor);\
var q = p.pathPoints[0]; q.anchor = [q.anchor[0] - 10, q.anchor[1]];\
vc.log(P.getByName('m').pathPoints[0].anchor); app.undo();",
);
assert_ne!(out[0], out[1], "the other member took the edit");
assert_eq!(art(&s), before);
let e = failure(
&mut s,
"var P = app.activeDocument.pathItems, p = P.getByName('edit'), m = P.getByName('m');\
var mp = m.pathPoints[0]; mp.anchor;\
var q = p.pathPoints[0]; q.anchor = [q.anchor[0] - 10, q.anchor[1]]; app.undo();\
mp.anchor;",
);
assert!(e.contains("Stale path point"), "{e}");
assert_eq!(art(&s), before);
}
/// Moving a group that holds the selected Global Edit member moves the other members too, so a
/// point read of another member before the move is stale afterwards.
#[test]
fn a_point_of_another_global_edit_member_is_stale_after_its_group_moves_and_undoes() {
let (mut s, a, b) = doc();
let c = rect(&mut s, 200.0, 100.0, 30.0, 40.0);
s.execute("object.setProps", &json!({"ids": [c.0], "name": "m"})).unwrap();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("object.group", &json!({})).unwrap();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let r = s.execute("select.globalEdit", &json!({})).unwrap();
assert_eq!(r["count"], json!(2), "{r}");
let before = art(&s);
let out = log(
&mut s,
"var P = app.activeDocument.pathItems, m = P.getByName('m');\
vc.log(m.pathPoints[0].anchor);\
app.activeDocument.groupItems[0].translate(10, 0);\
vc.log(P.getByName('m').pathPoints[0].anchor); app.undo();",
);
assert_ne!(out[0], out[1], "the other member took the move");
assert_eq!(art(&s), before);
let e = failure(
&mut s,
"var P = app.activeDocument.pathItems, m = P.getByName('m');\
var mp = m.pathPoints[0]; mp.anchor;\
app.activeDocument.groupItems[0].translate(10, 0); app.undo();\
mp.anchor;",
);
assert!(e.contains("Stale path point"), "{e}");
assert_eq!(art(&s), before);
}
/// [`doc`] with pattern `Dots` and spot swatch `Ink`, and path `a` with no fill or stroke.
fn doc_with_paints() -> (Session, NodeId) {
let (mut s, a, _) = doc();
+3 -1
View File
@@ -3685,7 +3685,9 @@ through `$`:
than the object model changed the path's points (a command run with `vc.run`, such as `path.setAnchors`,
`object.move` or `edit.undo`); points stay valid through the object model's other changes to the path or to an
object that holds it, such as `translate()`. An exception applies when editing another path in an Objects on
Path group moves a path inside that group. Its existing `PathPoint` handles throw `Stale path point`.
Path group moves a path inside that group, and when Global Edit changes another member's path points.
Their existing `PathPoint` handles throw `Stale path point`. An appearance-only change, such as a fill change,
leaves the handles valid.
Read those points again from `pathPoints`. Reading a path's points first writes any waiting point changes of
another path in the same Objects on Path group. Every point of a path selected as a whole is a selected anchor point,
and the endpoints of selected segments are not. Independently selected anchors remain selected alongside segment
+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`). `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. A `PathPoint` of another Global Edit member goes stale when Global Edit changes its path's points. `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`.