mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 05:22:58 -05:00
Scripts: palette events keep their file access, hide and enabled checks
- update() takes a waiting palette event only when the run's file access roots reach the same files as the event's, so a handler never runs with less access than its palette was shown with. - A palette event is no longer delivered to a handler after its palette was hidden and shown again, or after a capturing listener disabled or hid the control or a group above it. - A limit that ends a handler update() took restores the run's own actions before the end-of-run refresh. - A palette refresh that fails reports no unhandled rejection. - A refused palette field text no longer replaces text typed after it. - The script.run, script.palette.event and docs texts describe update() delivery, list staleness after item edits, and repeating a click or close dropped with an oversized text.
This commit is contained in:
1 parent
cbf870502a
commit
2cf9f56194
11 files changed
+158
-37
No files matched your search
@@ -32,7 +32,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Run Script",
|
||||
[],
|
||||
None,
|
||||
"{path?: a script file (.js, .mjs or .jsx) | source?: the script's text (exactly one of the two), installed?: true or false (default false; true with a path that script.listInstalled gave: the file is read once, checked as File › Scripts checks it, and that text runs, its #include lines and $.evalFile reading in the folder that read found; a file that is no longer a listed script ends with \"the script is no longer in the Scripts folder\" and nothing runs), module?: true or false (default true for a path ending in .mjs, false otherwise; true runs the file or source as a .mjs file runs, as a module, and a source run this way imports no files), name?: the name errors and the report use (default: the script's #script line, else the path's file name, or \"script\"), args?: {…} (at most 1 MiB as JSON; vc.args in the script), answers?: [{kind: alert|confirm|prompt|window, value: \"ok\" (alert) | true or false (confirm) | text or null (prompt) | [{control, event: click} | {control, event: change, value: text, number, item index or null} | {event: close}] (window: the steps of one show(), control being a control's name, or the text of a control without a name)}] (for a run with nobody to ask: the answers to its dialogs, in order; at most 10000 and 1 MiB as JSON; refused in the app, where the person answers; an empty object is an empty list), actions?: [{set, name, steps: [{command, params?, step?: the step's place in the action, a whole number from 1 (default its place in the list)}]}] (the actions app.doScript(action, set, dialogs?) plays, matched by their exact names; a command.batch step gives its own steps; at most 4096 actions, 10000 steps an action, 100000 steps in all and 16 MiB as JSON; in the app, the Actions panel's actions with their included steps, which a caller's list replaces), maxFuel?: whole number from 1 to 100000000000 (instructions in all; default 1000000000)} run a JavaScript file against the open documents, through the vc object: vc.run(id, params) runs a command and returns its result, a failed command throws an error the script can catch and puts back the documents and the session state it changed, while any file it wrote stays written and is named; vc.document is a snapshot of the active document or null; vc.commands lists the commands a script may run; vc.log(value) adds to the report and the Script Console (script.console); $.write(...values) writes the values to the Script Console as String(value) gives them, and $.writeln(...values) does the same and ends the line; $.evalFile(path, timeout?) runs a file with the same globals and returns its last value (timeout, in milliseconds from 0, is taken and not waited on), an absolute path in a File's URI notation is read too, with escapes decoded and /c/... naming drive C: on Windows, $.fileName is the file of the code that reads it (the file being run for code that eval or Function compiled; empty for code compiled from a script given as text), $.includePath the #includepath list and $.engineName the engine's name (VectorCraft without #targetengine); alert(message[, title, errorIcon]), confirm(message[, noAsDflt, title]) and prompt(message, preset[, title]) open a dialog with a Stop button (default title \"Script Alert\"; message and preset as String(value) gives them; errorIcon and noAsDflt as Boolean(value) gives them; No is the default with noAsDflt): alert returns undefined, confirm true for Yes and false for No, prompt the field's text for OK and null for Cancel; in the app the run waits at the call for the person's answer and Stop ends it as script.stop does, a dialog cannot open inside a callback of a built-in, a getter, a conversion or a file $.evalFile runs and throws there (an #include file's code is the script's own and can), and a run with nobody to ask takes the next of answers, and ends when none is left or the next is for another kind of dialog, or when the script ends with answers unused; new Window(\"dialog\", title) builds a ScriptUI dialog with add(type, bounds, text or items or value, properties) for group, panel, statictext, edittext, button, checkbox, radiobutton, dropdownlist, listbox (one selection), slider and progressbar (a group takes properties third, or fourth after a third that is not an object, and a list may take them there with properties.items), at most 512 controls 16 deep, 1024 list items and 16 KiB a text (other types and windows throw that they are not available yet); new Window and add also take a resource string such as \"dialog { g: Group { b: Button { text: 'OK' } } }\" in place of the type, which adds each control it lists through add and sets it and each other value as the property of its name (properties gives the creation properties and a list's items its item texts; at most 1 MiB nested 64 deep, and a malformed one throws a SyntaxError); preferredSize, size, minimumSize and maximumSize start with width and height -1 (left to the layout), lists have find and remove, containers remov
Line truncated
|
||||
"{path?: a script file (.js, .mjs or .jsx) | source?: the script's text (exactly one of the two), installed?: true or false (default false; true with a path that script.listInstalled gave: the file is read once, checked as File › Scripts checks it, and that text runs, its #include lines and $.evalFile reading in the folder that read found; a file that is no longer a listed script ends with \"the script is no longer in the Scripts folder\" and nothing runs), module?: true or false (default true for a path ending in .mjs, false otherwise; true runs the file or source as a .mjs file runs, as a module, and a source run this way imports no files), name?: the name errors and the report use (default: the script's #script line, else the path's file name, or \"script\"), args?: {…} (at most 1 MiB as JSON; vc.args in the script), answers?: [{kind: alert|confirm|prompt|window, value: \"ok\" (alert) | true or false (confirm) | text or null (prompt) | [{control, event: click} | {control, event: change, value: text, number, item index or null} | {event: close}] (window: the steps of one show(), control being a control's name, or the text of a control without a name)}] (for a run with nobody to ask: the answers to its dialogs, in order; at most 10000 and 1 MiB as JSON; refused in the app, where the person answers; an empty object is an empty list), actions?: [{set, name, steps: [{command, params?, step?: the step's place in the action, a whole number from 1 (default its place in the list)}]}] (the actions app.doScript(action, set, dialogs?) plays, matched by their exact names; a command.batch step gives its own steps; at most 4096 actions, 10000 steps an action, 100000 steps in all and 16 MiB as JSON; in the app, the Actions panel's actions with their included steps, which a caller's list replaces), maxFuel?: whole number from 1 to 100000000000 (instructions in all; default 1000000000)} run a JavaScript file against the open documents, through the vc object: vc.run(id, params) runs a command and returns its result, a failed command throws an error the script can catch and puts back the documents and the session state it changed, while any file it wrote stays written and is named; vc.document is a snapshot of the active document or null; vc.commands lists the commands a script may run; vc.log(value) adds to the report and the Script Console (script.console); $.write(...values) writes the values to the Script Console as String(value) gives them, and $.writeln(...values) does the same and ends the line; $.evalFile(path, timeout?) runs a file with the same globals and returns its last value (timeout, in milliseconds from 0, is taken and not waited on), an absolute path in a File's URI notation is read too, with escapes decoded and /c/... naming drive C: on Windows, $.fileName is the file of the code that reads it (the file being run for code that eval or Function compiled; empty for code compiled from a script given as text), $.includePath the #includepath list and $.engineName the engine's name (VectorCraft without #targetengine); alert(message[, title, errorIcon]), confirm(message[, noAsDflt, title]) and prompt(message, preset[, title]) open a dialog with a Stop button (default title \"Script Alert\"; message and preset as String(value) gives them; errorIcon and noAsDflt as Boolean(value) gives them; No is the default with noAsDflt): alert returns undefined, confirm true for Yes and false for No, prompt the field's text for OK and null for Cancel; in the app the run waits at the call for the person's answer and Stop ends it as script.stop does, a dialog cannot open inside a callback of a built-in, a getter, a conversion or a file $.evalFile runs and throws there (an #include file's code is the script's own and can), and a run with nobody to ask takes the next of answers, and ends when none is left or the next is for another kind of dialog, or when the script ends with answers unused; new Window(\"dialog\", title) builds a ScriptUI dialog with add(type, bounds, text or items or value, properties) for group, panel, statictext, edittext, button, checkbox, radiobutton, dropdownlist, listbox (one selection), slider and progressbar (a group takes properties third, or fourth after a third that is not an object, and a list may take them there with properties.items), at most 512 controls 16 deep, 1024 list items and 16 KiB a text (other types and windows throw that they are not available yet); new Window and add also take a resource string such as \"dialog { g: Group { b: Button { text: 'OK' } } }\" in place of the type, which adds each control it lists through add and sets it and each other value as the property of its name (properties gives the creation properties and a list's items its item texts; at most 1 MiB nested 64 deep, and a malformed one throws a SyntaxError); preferredSize, size, minimumSize and maximumSize start with width and height -1 (left to the layout), lists have find and remove, containers remov
Line truncated
|
||||
always,
|
||||
run
|
||||
),
|
||||
@@ -77,7 +77,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Script Palette Event",
|
||||
[],
|
||||
None,
|
||||
"{palette: an id script.palettes lists, event: click|change|close, control?: a control (its index, name or text; click and change), value?: the new value (an edit field's text, a slider's number, or a list's item index or null; change)} give a shown palette a click, a change or a close, as the person does: it runs as a run of its own in the palette's engine, with its report like script.run's, once no run is going, oldest first; a newer click on the same control, change of it or close of the same palette replaces the most recent waiting event of that kind for that control or palette only when it has the same file access roots; otherwise the new event waits at the end of the line (merged: false); a click or close takes its place only if no change of its palette waits after it, otherwise it waits as a new event (merged: false); a list's change ends its run with an error when the list holds other items by then; dialogs throw in the handler in the app, and with nobody to ask the run ends at one; a hidden palette, a control that is disabled, hidden or cannot take the event, and a 65th waiting event are refused, and with nobody to ask so is an event while an undo group or a drag in a document other than the active one is open → in the app {waiting: true, merged: whether it took the place of a waiting event, waitingEvents}, and the report later in ui.inspect's scriptReport; with nobody to ask, the waiting events run in order and the answer is the report of the run that handled this event (or its error): its own run, or a run of the same engine whose own code took it with update(), which gives it no report or undo step of its own; an event dropped without a run, because an earlier handler disabled, hid or removed its control or hid or closed its palette, ends with an error; an event whose run starts and finds its control, or a group above it, disabled or hidden by a getter read for the palette, or whose `enabled` or `visible` state a getter gives, runs no handler",
|
||||
"{palette: an id script.palettes lists, event: click|change|close, control?: a control (its index, name or text; click and change), value?: the new value (an edit field's text, a slider's number, or a list's item index or null; change)} give a shown palette a click, a change or a close, as the person does: it runs as a run of its own in the palette's engine, with its report like script.run's, once no run is going, oldest first; a newer click on the same control, change of it or close of the same palette replaces the most recent waiting event of that kind for that control or palette only when it has the same file access roots; otherwise the new event waits at the end of the line (merged: false); a click or close takes its place only if no change of its palette waits after it, otherwise it waits as a new event (merged: false); a list's change ends its run with an error when a script added or removed the list's items, or changed an item's text, by then, even if the list again holds the same texts; dialogs throw in the handler in the app, and with nobody to ask the run ends at one; a hidden palette, a control that is disabled, hidden or cannot take the event, and a 65th waiting event are refused, and with nobody to ask so is an event while an undo group or a drag in a document other than the active one is open → in the app {waiting: true, merged: whether it took the place of a waiting event, waitingEvents}, and the report later in ui.inspect's scriptReport; with nobody to ask, the waiting events run in order and the answer is the report of the run that handled this event (or its error): its own run, or a run of the same engine whose own code took it with update(), which gives it no report or undo step of its own; an event dropped without a run, because an earlier handler disabled, hid or removed its control or hid or closed its palette, ends with an error; an event whose run starts and finds its control, or a group above it, disabled or hidden by a getter read for the palette, or whose `enabled` or `visible` state a getter gives, runs no handler",
|
||||
always,
|
||||
palette_event
|
||||
),
|
||||
|
||||
@@ -290,11 +290,6 @@ impl ScopeHandle {
|
||||
Self(Some(scope), GATE.with(|g| g.borrow().clone()), GATE_READS_EXEMPT.with(std::cell::Cell::get))
|
||||
}
|
||||
|
||||
/// Whether this scope allows everything the calling thread's scope allows ([`ScopeHandle::covers`]).
|
||||
pub(crate) fn covers_current(&self) -> bool {
|
||||
self.covers(&Self::capture())
|
||||
}
|
||||
|
||||
/// Whether this scope allows everything `other` allows: its roots are none, or each root of
|
||||
/// `other` lies inside one of its roots of the same kind, and its script gate is none or the
|
||||
/// same gate.
|
||||
@@ -304,12 +299,25 @@ impl ScopeHandle {
|
||||
(Some(a), Some(b)) => Arc::ptr_eq(a, b),
|
||||
(Some(_), None) => false,
|
||||
};
|
||||
let roots = match (self.roots(), other.roots()) {
|
||||
gate && self.roots_cover(other)
|
||||
}
|
||||
|
||||
/// Whether this scope's roots are none, or each root of `other` lies inside one of its roots
|
||||
/// of the same kind.
|
||||
fn roots_cover(&self, other: &Self) -> bool {
|
||||
match (self.roots(), other.roots()) {
|
||||
(None, _) => true,
|
||||
(Some(a), Some(b)) => Arc::ptr_eq(&a, &b) || a.contains(&b),
|
||||
(Some(_), None) => false,
|
||||
};
|
||||
gate && roots
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether this scope allows everything the calling thread's scope allows
|
||||
/// ([`ScopeHandle::covers`]) and the calling thread's roots cover this scope's roots too, so
|
||||
/// work run in the calling thread's scope reaches the same files this scope reaches.
|
||||
pub(crate) fn matches_current(&self) -> bool {
|
||||
let current = Self::capture();
|
||||
self.covers(¤t) && current.roots_cover(self)
|
||||
}
|
||||
|
||||
/// Whether this scope and `other` allow the same: each covers the other, and reads are exempt
|
||||
|
||||
@@ -2988,6 +2988,12 @@ fn run_slice(s: &mut Session, job: &mut Job) -> std::result::Result<std::result:
|
||||
}
|
||||
Ok(progress)
|
||||
});
|
||||
// A limit that ends a palette's handler which `update()` took leaves the handler's
|
||||
// actions in place of the run's: once the run ends, the refresh's getters play the
|
||||
// run's own.
|
||||
if !matches!(progress, Ok(Progress::Paused)) {
|
||||
*host.palette_actions.borrow_mut() = None;
|
||||
}
|
||||
match progress {
|
||||
// The palettes of a named engine show the controls as the run left them. A getter
|
||||
// the refresh reads may change points, which are written before the run ends.
|
||||
|
||||
@@ -293,9 +293,11 @@ impl Palettes {
|
||||
}
|
||||
|
||||
/// The place of the oldest event for a palette of `engine`, when a palette's `update()` in a
|
||||
/// run of that engine may take it ([`Palettes::next_of`]).
|
||||
/// run of that engine may take it ([`Palettes::next_of`]): the run reaches the same files the
|
||||
/// event's scope reaches, so the handler runs with neither more nor less access than in a run
|
||||
/// of its own. Any other event waits for a run of its own.
|
||||
fn oldest_for(&self, engine: &str) -> Option<usize> {
|
||||
self.waiting.iter().position(|q| q.scope.covers_current() && self.list.iter().any(|p| p.id == q.palette && p.engine == engine))
|
||||
self.waiting.iter().position(|q| q.scope.matches_current() && self.list.iter().any(|p| p.id == q.palette && p.engine == engine))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@ fn repeated_clicks_and_closes_merge_after_the_last_change_of_their_palette() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_takes_events_whose_roots_grant_all_the_run_s_roots_grant() {
|
||||
fn update_takes_only_events_whose_roots_grant_what_the_run_s_roots_grant() {
|
||||
let mut s = one_doc();
|
||||
run_in_app(
|
||||
&mut s,
|
||||
@@ -403,12 +403,20 @@ fn update_takes_events_whose_roots_grant_all_the_run_s_roots_grant() {
|
||||
let wide = crate::file_access::AutomationRoots::new(&[&base], &[]).unwrap().unwrap();
|
||||
let same = crate::file_access::AutomationRoots::new(&[&base], &[]).unwrap().unwrap();
|
||||
let narrow = crate::file_access::AutomationRoots::new(&[&inner], &[]).unwrap().unwrap();
|
||||
for (run_roots, what) in [(same, "the same roots made again"), (narrow, "roots inside the event's roots")] {
|
||||
assert_eq!(crate::file_access::confine(Some(&wide), || s.script_palette_event(id, UiEvent::Click(1))), Ok(Waiting::Added));
|
||||
let report = crate::file_access::confine(Some(&run_roots), || run_in_app(&mut s, "#targetengine contain\np.update(); vc.log('after');"));
|
||||
assert_eq!(report["log"], json!(["clicked", "after"]), "{what}: {report}");
|
||||
assert_eq!(s.script_palette_events_waiting(), 0, "{what}");
|
||||
}
|
||||
assert_eq!(crate::file_access::confine(Some(&wide), || s.script_palette_event(id, UiEvent::Click(1))), Ok(Waiting::Added));
|
||||
let report = crate::file_access::confine(Some(&same), || run_in_app(&mut s, "#targetengine contain\np.update(); vc.log('after');"));
|
||||
assert_eq!(report["log"], json!(["clicked", "after"]), "the same roots made again: {report}");
|
||||
assert_eq!(s.script_palette_events_waiting(), 0);
|
||||
// A run whose roots lie inside the event's roots would run the handler with less access than
|
||||
// the event was given: the event waits for a run of its own.
|
||||
assert_eq!(crate::file_access::confine(Some(&wide), || s.script_palette_event(id, UiEvent::Click(1))), Ok(Waiting::Added));
|
||||
let report = crate::file_access::confine(Some(&narrow), || run_in_app(&mut s, "#targetengine contain\np.update(); vc.log('after');"));
|
||||
assert_eq!(report["log"], json!(["after"]), "roots inside the event's roots: {report}");
|
||||
assert_eq!(s.script_palette_events_waiting(), 1);
|
||||
crate::file_access::confine(Some(&wide), || {
|
||||
assert!(s.script_palette_start().expect("the click starts its run").is_ok());
|
||||
assert_eq!(pump(&mut s).expect("the handler ended").unwrap()["log"], json!(["clicked"]));
|
||||
});
|
||||
let _ = std::fs::remove_dir(inner);
|
||||
}
|
||||
|
||||
@@ -718,6 +726,22 @@ fn after_a_handler_that_update_runs_throws_the_run_plays_its_own_actions() {
|
||||
assert_eq!(objects(&s), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn after_a_limit_ends_a_handler_that_update_runs_the_refresh_plays_the_run_s_own_actions() {
|
||||
let mut s = one_doc();
|
||||
let (id, _) = acts_palette(&mut s, "for (;;) {}");
|
||||
run(
|
||||
&mut s,
|
||||
"#targetengine acts\nvar played = 'none'; Object.defineProperty(p, 'text', {get: function () { \
|
||||
try { app.doScript('Box', 'Set'); played = 'palette'; } catch (e) { played = 'own'; } return 'P'; }});",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(s.script_palette_event(id, UiEvent::Click(1)), Ok(Waiting::Added));
|
||||
assert!(run(&mut s, "#targetengine acts\nplayed = 'none'; p.update();").is_err(), "the handler's loop ends the run");
|
||||
let log = run(&mut s, "#targetengine acts\nvc.log(played);").unwrap()["log"].clone();
|
||||
assert_eq!(log, json!(["own"]), "the refresh after the limit plays the run's own actions, not the palette's");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_handler_plays_the_actions_of_the_run_that_showed_its_palette() {
|
||||
let mut s = one_doc();
|
||||
|
||||
@@ -751,8 +751,15 @@ impl Realm {
|
||||
self.rejections = self.interp.unhandled();
|
||||
Ok(())
|
||||
}
|
||||
Err(Abrupt::Limit(LimitKind::Fuel)) if total > cap => self.outcome(Err(Abrupt::Limit(LimitKind::Unbroken))).map(drop),
|
||||
Err(e) => self.outcome(Err(e)).map(drop),
|
||||
// A refresh that fails reports no rejection, as after any failed run.
|
||||
Err(Abrupt::Limit(LimitKind::Fuel)) if total > cap => {
|
||||
self.rejections = (Vec::new(), 0);
|
||||
self.outcome(Err(Abrupt::Limit(LimitKind::Unbroken))).map(drop)
|
||||
}
|
||||
Err(e) => {
|
||||
self.rejections = (Vec::new(), 0);
|
||||
self.outcome(Err(e)).map(drop)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,10 @@
|
||||
//! gives `paletteClose` the id; a `close()` while `onClose` runs does nothing more. The realm keeps
|
||||
//! each palette the host shows until it closes. `Window.__vcPaletteEvent()` takes an event from the
|
||||
//! host's `paletteEvent` (`{palette, event, id, value, element}`, or `null`, with `element` the id
|
||||
//! of the control), gives it to that palette as a
|
||||
//! dialog takes one, and then gives `paletteUpdate` each palette's description; `add()` on a shown
|
||||
//! palette does the same for that palette, so the host's list of its controls stays in step.
|
||||
//! of the control), and gives it to that palette as a dialog takes one, without giving
|
||||
//! `paletteUpdate` any description: the host gets the palettes' controls when the run ends
|
||||
//! ([`crate::Realm::refresh_script_ui`]). `add()` on a shown palette gives `paletteUpdate` that
|
||||
//! palette's description, so the host's list of its controls stays in step.
|
||||
//! `update()` on a shown palette, or on a `group` or a `panel` in one, takes each event that waits
|
||||
//! for a palette of the run's engine from the host's `paletteTake` (as `paletteEvent` gives it, or
|
||||
//! `null`) and gives it to its palette, while the host's `palettePending` says one waits, giving
|
||||
@@ -134,6 +135,9 @@ const LIST: &str = "__vcList";
|
||||
const PALETTE_ID: &str = "__vcPaletteId";
|
||||
const SHOWN: &str = "__vcShown";
|
||||
const IN_CLOSE: &str = "__vcInClose";
|
||||
/// How many times a palette was hidden: an event it took before a hide is not its event after a
|
||||
/// later `show()`.
|
||||
const HIDES: &str = "__vcHides";
|
||||
/// How many times a list's items were added or removed: a palette's waiting change of the list is
|
||||
/// for the items it had then.
|
||||
const REVISION: &str = "__vcRevision";
|
||||
@@ -1263,15 +1267,33 @@ fn dispatch(i: &mut Interp, target: ObjId, ty: &str, callback: &str) -> JsResult
|
||||
/// always takes it.
|
||||
type Taker = Option<(ObjId, ObjId, ObjId)>;
|
||||
|
||||
/// Does the palette of `taker` still take its event and hold its control? Always true for a
|
||||
/// dialog.
|
||||
/// Does the palette of `taker` still take its event and hold its control, with the control and
|
||||
/// every container above it enabled and visible as they are now, read without running a getter
|
||||
/// ([`plain_state`])? Always true for a dialog.
|
||||
fn takes(i: &mut Interp, taker: Taker) -> JsResult<bool> {
|
||||
match taker {
|
||||
Some((win, ev, c)) => Ok(still_takes(i, win, ev, None)? && holds(i, win, c)?),
|
||||
Some((win, ev, c)) => Ok(still_takes(i, win, ev, None)? && holds(i, win, c)? && live_up(i, win, c)?),
|
||||
None => Ok(true),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `c` and each container above it, up to and including `top`, are enabled and visible,
|
||||
/// read without running a getter ([`plain_state`]).
|
||||
fn live_up(i: &Interp, top: ObjId, c: ObjId) -> JsResult<bool> {
|
||||
let mut at = c;
|
||||
for _ in 0..=MAX_DEPTH + 1 {
|
||||
if !plain_state(i, at, "enabled")? || !plain_state(i, at, "visible")? {
|
||||
return Ok(false);
|
||||
}
|
||||
if at == top {
|
||||
return Ok(true);
|
||||
}
|
||||
let Some(p) = object_slot(i, at, PARENT)? else { return Ok(false) };
|
||||
at = p;
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// [`dispatch`] for the event a palette takes (`taker`): no handler or listener runs once a getter,
|
||||
/// a handler or a listener of the event closed the palette or took the event's control out of it.
|
||||
/// → `None` when that happened.
|
||||
@@ -1636,6 +1658,8 @@ fn hide(i: &mut Interp, this: Value, _: &[Value], _: bool) -> JsResult<Value> {
|
||||
let f = host_fn(i, "paletteHide")?;
|
||||
i.call(&f, &Value::Undefined, &[Value::Number(id)])?;
|
||||
set_slot(i, o, SHOWN, Value::Bool(false))?;
|
||||
let hides = number_slot(i, o, HIDES)? + 1.0;
|
||||
set_slot(i, o, HIDES, Value::Number(hides))?;
|
||||
i.put(o, key("visible"), Value::Bool(false), true)?;
|
||||
}
|
||||
Ok(Value::Undefined)
|
||||
@@ -1892,6 +1916,9 @@ fn deliver(i: &mut Interp, answer: Value) -> JsResult<Value> {
|
||||
}
|
||||
}
|
||||
let Some(win) = win else { return Ok(Value::Undefined) };
|
||||
// A hide from here on, even one a later show() follows, ends the palette's hold on the event.
|
||||
let hides = number_slot(i, win, HIDES)?;
|
||||
set_slot(i, ev, HIDES, Value::Number(hides))?;
|
||||
let event = match slot(i, ev, "event")? {
|
||||
Value::String(s) => s.to_rust_string(),
|
||||
_ => String::new(),
|
||||
@@ -2022,13 +2049,14 @@ fn holds_value(i: &mut Interp, win: ObjId, held: &[Value], at: usize) -> JsResul
|
||||
}
|
||||
|
||||
/// Whether the window `win` still takes the event `ev`: a dialog (`keep` is `Some`) always does,
|
||||
/// and a palette only while the host shows it under the id the event names. A getter or a handler
|
||||
/// run for the event may have closed or hidden the palette.
|
||||
/// and a palette only while the host shows it under the id the event names and it has not been
|
||||
/// hidden since it took the event. A getter or a handler run for the event may have closed or
|
||||
/// hidden the palette, and shown it again.
|
||||
fn still_takes(i: &mut Interp, win: ObjId, ev: ObjId, keep: Option<&[Value]>) -> JsResult<bool> {
|
||||
if keep.is_some() {
|
||||
return Ok(true);
|
||||
}
|
||||
if !slot(i, win, SHOWN)?.truthy() {
|
||||
if !slot(i, win, SHOWN)?.truthy() || number_slot(i, ev, HIDES)? != number_slot(i, win, HIDES)? {
|
||||
return Ok(false);
|
||||
}
|
||||
let id = slot(i, ev, "palette")?;
|
||||
|
||||
@@ -1223,6 +1223,51 @@ fn a_palette_event_does_not_run_a_handler_whose_getter_hid_the_palette() {
|
||||
assert_eq!(r.run("[reads, clicks].join()").unwrap(), JsValue::String("1,0".into()), "the handler read from a hidden palette does not run");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_palette_event_does_not_run_a_handler_once_a_listener_hid_and_showed_the_palette_again() {
|
||||
let (mut r, _) = palette_realm(vec![palette_event(1.0, click(1))]);
|
||||
r.run(
|
||||
"var p = new Window('palette'); var b = p.add('button', undefined, 'Go'); var clicks = 0, heard = 0; \
|
||||
p.addEventListener('click', function () { heard++; p.hide(); p.show(); }, true); \
|
||||
b.onClick = function () { clicks++; }; p.show();",
|
||||
)
|
||||
.unwrap();
|
||||
r.run("Window.__vcPaletteEvent();").unwrap();
|
||||
assert_eq!(
|
||||
r.run("[heard, clicks, p.visible].join()").unwrap(),
|
||||
JsValue::String("1,0,true".into()),
|
||||
"a click the palette took before a hide is not its click after the palette shows again"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_palette_event_does_not_run_a_handler_once_a_capturing_listener_disabled_its_group() {
|
||||
let (mut r, _) = palette_realm(vec![palette_event(1.0, click(2))]);
|
||||
r.run(
|
||||
"var p = new Window('palette'); var g = p.add('group'); var b = g.add('button', undefined, 'Go'); var clicks = 0, heard = 0; \
|
||||
g.addEventListener('click', function () { heard++; g.enabled = false; }, true); \
|
||||
b.onClick = function () { clicks++; }; p.show();",
|
||||
)
|
||||
.unwrap();
|
||||
r.run("Window.__vcPaletteEvent();").unwrap();
|
||||
assert_eq!(r.run("[heard, clicks].join()").unwrap(), JsValue::String("1,0".into()), "a control in a disabled group takes no click");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_palette_refresh_that_fails_reports_no_rejection() {
|
||||
let (mut r, _) = palette_realm(Vec::new());
|
||||
r.add_es2015();
|
||||
r.run(
|
||||
"var armed = false; var p = new Window('palette'); p.add('button', undefined, 'Go'); \
|
||||
Object.defineProperty(p, 'text', {get: function () { if (armed) { throw new Error('getter'); } return 'P'; }}); \
|
||||
p.show(); Promise.reject(new Error('early')); armed = true;",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(r.unhandled_rejection_count(), 1, "the run left the rejection unhandled");
|
||||
assert!(r.refresh_script_ui().is_err());
|
||||
assert_eq!((r.unhandled_rejections().len(), r.unhandled_rejection_count()), (0, 0), "a failed refresh reports no rejection");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_palette_list_change_runs_no_on_change_once_an_item_s_text_getter_removed_the_list() {
|
||||
let (mut r, _) = palette_realm(vec![seen_list_change(1.0)]);
|
||||
|
||||
@@ -405,8 +405,9 @@ fn give(
|
||||
}
|
||||
Err(error) => {
|
||||
if let Some((i, text)) = change {
|
||||
// A text typed after the refused one stays in the field.
|
||||
if let Some((n, text)) = p.dialog.nodes.get(i).zip(text) {
|
||||
drafts.insert(n.id, text);
|
||||
drafts.entry(n.id).or_insert(text);
|
||||
}
|
||||
*change_refused = true;
|
||||
}
|
||||
|
||||
+5
-5
@@ -4135,8 +4135,8 @@ the same controls, handlers and limits:
|
||||
`update()` on the palette, or on a group or panel in it, first runs the handlers of the clicks, changes and
|
||||
closes that wait for the palettes of the run's engine, oldest first, so a Cancel button's `onClick` can stop
|
||||
a loop that calls `update()` (https://extendscript.docsforadobe.dev/user-interface-tools/window-object/).
|
||||
`update()` takes eligible events oldest first. Events whose recorded file access scopes do not cover the run's
|
||||
scope stay queued for runs of their own, while later eligible events for the same engine can run. Events within
|
||||
`update()` takes eligible events oldest first. Events whose recorded file access scopes do not reach the same
|
||||
files as the run's scope stay queued for runs of their own, while later eligible events for the same engine can run. Events within
|
||||
one scope keep their order. A desktop event keeps the scope in force when the widget records it, even if the app
|
||||
hands it to the engine under different automation roots. Each deferred event runs in its recorded scope within
|
||||
the scope in force when its run starts. Each one is checked against the palette as the script and the
|
||||
@@ -4174,9 +4174,9 @@ the same controls, handlers and limits:
|
||||
or `visible` state a getter gives is shown disabled or hidden, and its events are dropped. A list's change is dropped, with no error and no handler run,
|
||||
when a script added or removed the list's items after the person chose and before the app put the change in
|
||||
line. Once the change waits in line, it ends its run with an error when a script added or removed the list's
|
||||
items, even if the list again holds the same texts, and when an item's text comes from a getter rather than a
|
||||
plain value. A text typed in a palette's field that is longer than 16 KiB stays in the field with the error in the status bar, and a click or close waits
|
||||
until it is fixed. An error in a handler that ends its run fails that run like any failed run, puts the
|
||||
items or changed an item's text, even if the list again holds the same texts, and when an item's text comes from a getter rather than a
|
||||
plain value. A text typed in a palette's field that is longer than 16 KiB stays in the field with the error in the status bar, and the click or close
|
||||
given with it is dropped: correct the text, then click or close again. An error in a handler that ends its run fails that run like any failed run, puts the
|
||||
documents back, and leaves the palette open. A handler that a palette's `update()` runs throws its error from
|
||||
that `update()` call: when the script catches it, the run goes on and keeps the handler's changes. In the app, `alert`, `confirm`, `prompt` and a dialog's `show()` throw inside a
|
||||
handler; with nobody to ask, a handler's run has no `answers` and ends at the first of them.
|
||||
|
||||
@@ -1178,7 +1178,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Plug-in, recovery and script report replies under `--automation-read-root`: `plugin.list`, `plugin.info` and `plugin.safeMode` name the plug-in folder, failed files, plug-in sources and disabled plug-ins' files outside the read roots by file name or `null`, `file.recovery.*` leave out a document's original file and the recovery folder outside them, and `ui.inspect`'s `scriptReport` names files a run wrote outside them by file name. `crates/engine/src/tests/plugins.rs` (`plugin_list_leaves_out_paths_outside_the_read_root`), `crates/engine/src/tests/recovery.rs` (`recovery_replies_leave_out_paths_outside_the_read_root`), `crates/ui-egui/src/tests/automation.rs` (`ui_inspect_script_report_leaves_out_files_outside_the_read_root`).
|
||||
- Scripts: `alert`, `confirm` and `prompt` open dialogs during a run, each with a Stop button that ends the run and puts every document back. In the app the run waits at the call for the person's answer; a run over MCP or the command line takes its answers in order from `script.run`'s `answers`, and the report lists each dialog with its answer. `crates/engine/src/tests/script_dialogs.rs`, `crates/ui-egui/src/tests/script_dialogs.rs`.
|
||||
- Scripts: ScriptUI's `new Window("dialog")` builds a modal dialog of groups, panels, static text, edit fields, buttons, check boxes, radio buttons, drop-down lists, list boxes, sliders and progress bars (https://extendscript.docsforadobe.dev/user-interface-tools/window-object/). `show()` waits for the person and runs the controls' `onClick`, `onChanging` and `onChange` handlers. The window's own callbacks are `onShow`, which runs when `show()` starts, and `onClose`, which runs before the dialog closes and keeps it open when it returns false. `show()` returns the result of `close(result)`, or 1 for the default button and 2 for the cancel button when the button has no `onClick` or click listener and no handler closed the dialog with another result. Controls also take `notify`, size objects a script can set one side of, lists' `find` and `remove`, and `addEventListener` for clicks and changes, which the dialog also takes for `show`; `Window.alert`, `Window.confirm` and `Window.prompt` open the script dialogs; a run over MCP or the command line takes the clicks and changes from a `window` answer. `new Window` and `add` also build a window or a control and the controls inside it from a resource specification (https://extendscript.docsforadobe.dev/user-interface-tools/resource-specifications/). Other control types throw that they are not available yet. `crates/js/src/scriptui_tests.rs`, `crates/engine/src/tests/script_scriptui.rs`, `crates/ui-egui/src/tests/script_window.rs`.
|
||||
- Scripts: ScriptUI's `new Window("palette")` makes a palette in a script whose `#targetengine` names an engine other than `main`, and the palette's `show()` shows it beside the documents, where it stays open after the run (https://extendscript.docsforadobe.dev/user-interface-tools/window-object/). Each click, change or close runs its handler as a run of its own in that engine, after any run that is going. A click or change is dropped when its control, or a group above it, is disabled or hidden once the palette is described for the event, or when a getter gives that `enabled` or `visible` state. A newer change for the same control takes a waiting change's place only when no click or close of that palette waits after the waiting change, and a newer click or close takes a waiting one's place only when no change of that palette waits after it; in both cases the two must be given under the same file access scope. `update()` on a palette, or on a group or panel in one, runs the handlers of the events that wait for the engine's palettes whose file access scopes cover the run's scope, so a Cancel button can stop a loop; an event given under narrower roots or another script gate waits for a run of its own instead. `update()` in the script's own code in the app also pauses the run so the app draws the palette, at most once every 16 ms; on a showing dialog it runs without an error. `close()` and the close box close a palette unless its `onClose` returns `false`; the end of its engine or the session closes it too. A session keeps at most 16 palettes and 64 waiting events. `script.palettes` and `script.palette.event` list and drive them. `crates/js/src/scriptui_tests.rs`, `crates/engine/src/tests/script_palettes.rs`.
|
||||
- Scripts: ScriptUI's `new Window("palette")` makes a palette in a script whose `#targetengine` names an engine other than `main`, and the palette's `show()` shows it beside the documents, where it stays open after the run (https://extendscript.docsforadobe.dev/user-interface-tools/window-object/). Each click, change or close runs its handler as a run of its own in that engine, after any run that is going, unless a run of that engine takes it first with `update()` (below), which runs the handler during that run. A click or change is dropped when its control, or a group above it, is disabled or hidden once the palette is described for the event, or when a getter gives that `enabled` or `visible` state. A newer change for the same control takes a waiting change's place only when no click or close of that palette waits after the waiting change, and a newer click or close takes a waiting one's place only when no change of that palette waits after it; in both cases the two must be given under the same file access scope. `update()` on a palette, or on a group or panel in one, runs the handlers of the events that wait for the engine's palettes whose file access scopes reach the same files as the run's scope, so a Cancel button can stop a loop; an event given under other roots or another script gate waits for a run of its own instead. `update()` in the script's own code in the app also pauses the run so the app draws the palette, at most once every 16 ms; on a showing dialog it runs without an error. `close()` and the close box close a palette unless its `onClose` returns `false`; the end of its engine or the session closes it too. A session keeps at most 16 palettes and 64 waiting events. `script.palettes` and `script.palette.event` list and drive them. `crates/js/src/scriptui_tests.rs`, `crates/engine/src/tests/script_palettes.rs`.
|
||||
- Parameter keys: the engine refuses a key that a command's params description doesn't name before the command runs, in every build and for every caller, including the app's own calls, the commands a command runs and the steps of `command.batch` and `action.batch`. An action recorded by an older version still plays from the Actions panel and the Batch dialog (`Session::replay`). `crates/engine/tests/it/param_keys.rs`.
|
||||
- Parameter key lookups: the engine reads the params description of each built-in command, with the descriptions its `…` entries name, once per process, and answers the key check and the `ids` and `id` questions of each later command from that reading. A plug-in command's description, and a description whose `…` entries name a plug-in command, are still read each time. The accepted keys, the answers and the error messages are the same. In a release build on a one-object document, `object.move` with `ids` and `dx` takes 48 µs of thread CPU time per command instead of 61 µs, and `select.set` with `ids` 2.3 µs instead of 3.2 µs (medians of 7 alternating runs of 20,000 commands in one process, measured while other builds were running; `tests::params_cache::bench_params_keys_once`). The time is saved per command, in scripts, batches and MCP or plug-in call loops, and does not grow with the size of the document. `crates/engine/src/tests/params_cache.rs` compares every built-in command's answers with those of a fresh parse.
|
||||
- Effect parameter types: `effect.apply`, `appearance.addEffect` and `effect.setParams` refuse an effect parameter of another type than the effect reads, for keys only the params text names too (the earlier 3D `perspective`, `lightAzimuth` and `lightElevation`, Scribble's `variation`, Outline Stroke's `width`, Gaussian Blur's `linear`), a Crop Marks `style` other than `roman` or `japanese`, and an installed plug-in effect's parameter of another type than its manifest gives it, in a `command.batch` step too, with the document and undo history unchanged; a replayed action still plays. `effect.setParams` checks the parameters against a Warp's new style, and refuses a `visible` that is not true or false, in a replayed action too. `crates/engine/src/tests/params.rs` (`an_effect_parameter_without_a_default_is_held_to_its_type`, `effect_commands_refuse_an_undefaulted_parameter_of_the_wrong_type`), `crates/engine/src/tests/plugins.rs` (`live_effect_plugins_reshape_editable_art_and_expand`), `crates/engine/src/cmd/effectcmd/tests.rs` (`set_params_refuses_a_visible_that_is_not_true_or_false`, `set_params_checks_the_effect_it_leaves`).
|
||||
|
||||
Reference in new issue
Block a user