Merge pull request #9289 from dotCooCoo/feat/scripts-app-redraw

Scripts: app.redraw returns without changing the documents
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 08:36:42 -08:00
commit 62716cacd2
5 files changed
+33 -2

No files matched your search

+8
View File
@@ -848,6 +848,13 @@ fn path_key(p: &str) -> String {
if windows { p.to_lowercase() } else { p }
}
/// `app.redraw()`: returns without changing anything. The app draws a frame between the run's
/// slices on its own, and it draws the documents as they were before the run until the run ends,
/// so there is nothing for the call to draw. It adds no undo step.
fn app_redraw(_: &Host, _: &[Data]) -> Answer {
Ok(Data::Undefined)
}
/// `app.getIsFileOpen(path)`: whether a document open in the run has the file `path`. The path is
/// compared as text with the documents' files and is not resolved; a document whose file the
/// automation read roots do not allow does not count, and that check can look the file up on disk.
@@ -2565,6 +2572,7 @@ fn classes(link: &Link) -> Vec<HostClass> {
("selection", property(l, app_selection, app_set_selection), typed("*")),
("coordinateSystem", property(l, app_coords, app_set_coords), typed("CoordinateSystem")),
("getIsFileOpen", method(l, app_is_open), returns("boolean", &[("filePath", "string")])),
("redraw", method(l, app_redraw), returns("undefined", &[])),
("executeMenuCommand", method(l, app_menu_command), returns("undefined", &[("menuCommandString", "string")])),
("toString", class_text("Application"), returns("string", &[])),
]);
+19
View File
@@ -394,6 +394,25 @@ fn an_opacity_a_graph_mark_already_has_replaces_the_one_its_series_keeps() {
assert_eq!(kept(&s), None);
}
/// `app.redraw()` returns `undefined` and leaves the art and the undo history as they were.
#[test]
fn redraw_returns_and_changes_nothing() {
let (mut s, _, top) = doc();
let (art, steps) = (format!("{:?}", s.active().unwrap().doc.layers), undo_steps(&s));
assert_eq!(log(&mut s, "vc.log(typeof app.redraw()); vc.log(app.redraw(1, 'x') === undefined);"), vec![json!("undefined"), json!(true)]);
assert_eq!(format!("{:?}", s.active().unwrap().doc.layers), art);
assert_eq!(undo_steps(&s), steps);
// In a run in the app, edits before and after the calls still end as one undo step.
s.script_frames = true;
let source = "var i = app.activeDocument.pageItems[0]; i.opacity = 40; app.redraw(); i.opacity = 30; app.redraw();";
assert_eq!(s.execute("script.run", &json!({"source": source, "name": "t.js"})).unwrap()["running"], true);
let ended = (0..10_000).find_map(|_| s.script_pump()).unwrap_or_else(|| panic!("the run did not end"));
ended.unwrap();
// The edit after the first call landed too: the opacity is below the 40% set before it.
assert!(s.active().unwrap().doc.node(top).unwrap().opacity < 0.4);
assert_eq!(undo_steps(&s), steps + 1);
}
/// Assigning an item the opacity it reports, rounded to four decimals, changes nothing.
#[test]
fn assigning_the_reported_opacity_changes_nothing() {
@@ -90,7 +90,7 @@ const INSIDE: &[(&str, &str)] = &[
(
"Application.prototype.",
"activeDocument activeDocument= beep beep= constructor coordinateSystem coordinateSystem= documents executeMenuCommand \
getIsFileOpen selection selection= toString typename",
getIsFileOpen redraw selection selection= toString typename",
),
("DocumentPreset.", "prototype"),
(
+4 -1
View File
@@ -2782,6 +2782,7 @@ other files through `$`:
- `app` is the application object the help page https://ai-scripting.docsforadobe.dev/jsobjref/Application/
describes: `app.documents`, `app.activeDocument` (assigning an open document makes it the active one),
`app.selection` (assigning it sets the active document's selection), `app.coordinateSystem`,
`app.redraw()`,
`app.getIsFileOpen(path)` and `app.executeMenuCommand(name)`. `executeMenuCommand` runs the command of a menu item
on the active document, as the type definitions at https://www.indesignjs.de/indesignapi/illustrator/illustrator.d.ts
describe the method, and takes these names from the list at
@@ -2921,7 +2922,9 @@ other files through `$`:
with `selected`. `getIsFileOpen` compares the path with the open documents' files as text (in a Windows path,
letter case is ignored and `\` matches `/`) and does not resolve the path it is given. A document counts only when
the automation read roots allow its file, and that check can look the document's file up on disk. A path with
`..`, a network path, a NUL character or more than 4,096 bytes throws an error. Some members the Application,
`..`, a network path, a NUL character or more than 4,096 bytes throws an error. `app.redraw()` returns `undefined`
and does not change the documents or add an undo step. In the app, the documents are drawn as they were before the
run until the run ends, with or without the call. Some members the Application,
Document and PageItem pages list, such as `Document.layers`, `PageItem.blendingMode`, `PageItem.rotate` and
`app.beep`, throw an error that says they are not available yet when they are read or assigned.
`hasOwnProperty` and `propertyIsEnumerable` are false for those members and true for every other member of an
+1
View File
@@ -1110,6 +1110,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Scripts: `PageItem.tags` reads, adds, renames and deletes an object's tags, name and value pairs that the native file keeps, and `Document.tags` reads, renames and deletes the tags of every page item but adds none (its `add` throws; a script adds a tag through the page item's `tags`), as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Tags/ and https://ai-scripting.docsforadobe.dev/jsobjref/Tag/ describe them, through `object.tags` and the `object.tag.*` commands, at most 64 tags an object (`docs/mcp.md`). `crates/engine/src/tests/script_tags.rs`.
- Scripts: the global `app` gives the open documents, new documents from a startup preset and a `DocumentPreset`, the active document, each document's selection and its page items with their names, notes, visibility, lock, opacity, position, size, bounds and stacking order, and moves and copies them into or beside other objects, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Application/, https://ai-scripting.docsforadobe.dev/jsobjref/Documents/, https://ai-scripting.docsforadobe.dev/jsobjref/DocumentPreset/, https://ai-scripting.docsforadobe.dev/jsobjref/Document/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/ and https://ai-scripting.docsforadobe.dev/jsobjref/GroupItem/ describe them; each change runs a command inside the run's transaction (`docs/mcp.md`). A script can check a member with `hasOwnProperty`, and can read a collection by name and name `activeDocument`, `documents` and `selection` without `app.` (https://ai-scripting.docsforadobe.dev/scriptingJavascript/objectReferences/). `app.executeMenuCommand` runs the menu items Select All, Deselect, Group, Ungroup, Make and Release Clipping Mask, Make and Release Compound Path, and Fit to Artwork Bounds by their menu command names (https://community.adobe.com/questions-652/a-list-of-illustrator-menu-commands-we-can-call-from-javascript-769510, https://gist.github.com/shalakolee/df3246659d4289eb99149b9ed00a00ee). The `parent` of a page item at the top of a layer is a `Layer` with `name`, `typename` and `toString`.
`Document.views` lists the document's drawn windows with their bounds, center, zoom and screen mode (https://ai-scripting.docsforadobe.dev/jsobjref/View/). Zoom follows each window's displayed percentage, including display density with Display Print Size at 100% Zoom enabled; bounds retain the physical camera scale. View objects keep their targets when windows are renumbered. View changes run no command, add no undo step, and remain when a script fails. A center outside the canvas after coordinate conversion throws a `RangeError`. `Document.layers`, `Document.activeLayer`, paths, type and the other classes are not there yet. `crates/engine/src/tests/script_dom.rs`.
- Scripts: `app.redraw()` (https://ai-scripting.docsforadobe.dev/jsobjref/Application/) returns without changing the documents or adding an undo step; the app goes on drawing the documents as they were before the run until the run ends. VectorCraft's own rule. `crates/engine/src/tests/script_dom.rs`.
- Scripts: a document's variables and data sets, the variables its page items are bound to, Lock Variables, and importing and exporting a variable library through a `File`, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Variables/, https://ai-scripting.docsforadobe.dev/jsobjref/Variable/, https://ai-scripting.docsforadobe.dev/jsobjref/Datasets/ and https://ai-scripting.docsforadobe.dev/jsobjref/Dataset/ describe them; `variable.setBinding` binds one object for one slot, and `dataset.update {name}` updates a data set that is not the active one (`docs/mcp.md`). `crates/engine/src/tests/script_variables.rs`.
- Scripts: Window › Script Console shows each run's `$.write` and `$.writeln` output, `vc.log` entries, uncaught error with the script's name, line and column, and a report of its time, host calls and slowest commands, keeping at most 2,048 lines and counting the lines it dropped. `script.run`'s report carries the same data, and `script.console`, `script.console.clear` and `ui.copyScriptConsole` read, clear and copy it. `crates/engine/src/tests/script_console.rs`.
- Scripts: the status bar translates its own words around a failed run's error and the app's own error messages, and shows text the script threw itself (a value, an error it made, or an error whose name or message it changed) as it is, even when that text reads like one of the app's messages. `script.run`'s report gives `messageOrigin` (`script` or `built-in`), and the advice about objects other applications give their scripts follows only the app's own reference errors. VectorCraft's own rule. `crates/js/src/interp_tests.rs`, `crates/engine/src/tests/script_run.rs`, `crates/ui-egui/src/chrome/tests.rs`.