mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-31 05:27:08 -06:00
fix(script): keep After Effects Undo command ID 16 stable (#812)
This commit is contained in:
@@ -1798,8 +1798,13 @@ var app = {
|
||||
beginSuppressDialogs: function () {},
|
||||
endSuppressDialogs: function () {},
|
||||
purge: function () { __call("edit.purge", { what: "all" }); },
|
||||
findMenuCommandId: function (name) { return __get("menuCommandId", { name: String(name) }); },
|
||||
findMenuCommandId: function (name) {
|
||||
// Well-known After Effects ids must not shift when EffectCraft registers a command.
|
||||
if (String(name) === "Undo") return 16;
|
||||
return __get("menuCommandId", { name: String(name) });
|
||||
},
|
||||
executeCommand: function (id) {
|
||||
if (id === 16) return __call("edit.undo", {});
|
||||
var cmd = typeof id === "number" ? __get("commandAt", { index: id }) : String(id);
|
||||
if (!cmd) throw __err("Unknown command id " + id);
|
||||
return __call(cmd, {});
|
||||
|
||||
@@ -730,3 +730,20 @@ fn import_options_sequence_picks_one_still_or_the_run() {
|
||||
assert_eq!(kind_of(&s, "shot_[0001-0003].png"), FootageKind::Sequence);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_undo_uses_stable_after_effects_command_id() {
|
||||
let mut s = session();
|
||||
let lookup = ok(&mut s, "app.findMenuCommandId('Undo')");
|
||||
assert_eq!(lookup.result, json!(16));
|
||||
// ID 16 used to index an unrelated command as the registry grew. It must
|
||||
// undo the preceding layer creation rather than dispatching by position.
|
||||
let r = ok(
|
||||
&mut s,
|
||||
"var c = app.project.items.addComp('Undo ID', 100, 100, 1, 1, 24); c.layers.addNull(); app.executeCommand(16); c.numLayers",
|
||||
);
|
||||
assert_eq!(r.result, json!(0));
|
||||
assert_eq!(s.project.comp(ItemId(1)).unwrap().layers.len(), 0);
|
||||
// Lookup of other command names still uses the existing registry.
|
||||
assert!(ok(&mut s, "app.findMenuCommandId('New Project')").result.as_u64().unwrap_or(0) > 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user