From dc569257e1515b9bd36b167d858bbcf2fdb4afe4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 11:58:38 -0800 Subject: [PATCH] Scripts: a Copy the run puts back leaves the clipboard as it was edit.copy, artboard.copy and artboard.cut now have the clipboard saved before them, as edit.cut and command.batch do. Before, a Copy whose result could not reach the script was put back without its clipboard, so the copy stayed on the clipboard and the run reported copied: true. --- crates/engine/src/script/mod.rs | 2 +- crates/engine/src/tests/script_dom_prefs.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/script/mod.rs b/crates/engine/src/script/mod.rs index 61f4f9d2ba..a6162b8b3c 100644 --- a/crates/engine/src/script/mod.rs +++ b/crates/engine/src/script/mod.rs @@ -630,7 +630,7 @@ impl World { /// The commands that can change the clipboard and still fail, or still be put back because their /// result cannot reach the script, and that do not put it back themselves. The clipboard can hold /// a great deal, so a savepoint copies it only for these. -const CAN_FAIL_AFTER_COPYING: &[&str] = &["action.batch", "command.batch", "edit.cut"]; +const CAN_FAIL_AFTER_COPYING: &[&str] = &["action.batch", "artboard.copy", "artboard.cut", "command.batch", "edit.copy", "edit.cut"]; /// The commands that remove a document's undo history, or the document: a savepoint keeps a whole /// copy of the histories for these. Any other command that removes or changes a step under the diff --git a/crates/engine/src/tests/script_dom_prefs.rs b/crates/engine/src/tests/script_dom_prefs.rs index bac0981ccc..dc2bacdff0 100644 --- a/crates/engine/src/tests/script_dom_prefs.rs +++ b/crates/engine/src/tests/script_dom_prefs.rs @@ -521,11 +521,13 @@ fn a_copy_or_cut_the_run_puts_back_is_not_reported() { let r = run( &mut s, "try { vc.run('command.batch', {commands: [{command: 'edit.copy', params: {}}]}); } catch (e) { vc.log(e.name); }\ - try { vc.run('edit.cut'); } catch (e) { vc.log(e.name); }", + try { vc.run('edit.cut'); } catch (e) { vc.log(e.name); }\ + try { vc.run('edit.copy'); } catch (e) { vc.log(e.name); }\ + try { vc.run('artboard.copy', {indices: [0]}); } catch (e) { vc.log(e.name); }", ); crate::script::TEST_RESULT_BYTES.with(|b| b.set(None)); let r = r.unwrap(); - assert_eq!(r["log"], json!(["RangeError", "RangeError"]), "{r}"); + assert_eq!(r["log"], json!(["RangeError", "RangeError", "RangeError", "RangeError"]), "{r}"); assert_eq!(r.get("copied"), None, "{r}"); assert_eq!(s.copies, copies); assert!(s.clipboard_copied);