Artboards: a Cut or Copy with the Artboard tool replays on its artboards

edit.copy and edit.cut chose the artboard route by the tool chosen, which
the journal does not record. A replay in a new session acted on the objects
selected there, or stopped with "nothing selected" when there were none.

With the Artboard tool chosen, both now record selectedArtboards and art in
the journal entry. A given selectedArtboards runs the artboard route with
any tool and needs only a document. A recorded action leaves both values
out, so it follows the tool chosen when it plays. Cut and Copy of objects
record nothing new.
This commit is contained in:
dotCooCoo
2026-11-06 21:35:41 -08:00
parent ff9deee46d
commit 72af76d418
7 changed files with 165 additions and 20 deletions
+116 -5
View File
@@ -328,23 +328,134 @@ fn artboard_commands_read_the_recorded_selected_artboards() {
}
}
/// `edit.copy` and `edit.cut` run the Artboard tool's copy and take no artboards, so their entries
/// stay as given.
/// A Cut or Copy with the Artboard tool replays on the artboards it took in a new session, where
/// another tool is chosen: with nothing selected there, and with an object selected that a Cut or
/// Copy of objects would take. What it pastes is the same.
#[test]
fn edit_copy_and_cut_with_the_artboard_tool_record_their_params_as_given() {
fn edit_copy_and_cut_with_the_artboard_tool_replay_on_its_artboards() {
for id in ["edit.copy", "edit.cut"] {
for select in ["select.all", "select.none"] {
let mut s = Session::new();
second_artboard_selected(&mut s);
s.execute(select, &json!({})).unwrap();
s.execute(id, &json!({})).unwrap();
let boards = if id == "edit.cut" { 2 } else { 3 };
assert_eq!(s.doc().unwrap().doc.artboards.len(), boards, "{id} after {select}");
assert_eq!(documents(&replayed(&s)), documents(&s), "{id} after {select}");
let entry = s.journal.last().unwrap().clone();
s.execute("edit.paste", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.artboards.len(), boards + 1, "{id} after {select}");
let r = replayed(&s);
assert_ne!(r.tool_id(), "artboard");
assert_eq!(documents(&r), documents(&s), "{id} after {select}");
assert_eq!(entry, (id.to_string(), json!({"selectedArtboards": [1], "art": true})), "{id} after {select}");
}
}
}
/// A Copy after a Paste takes the pasted artboards, which the Artboard tool selected, and so does its
/// replay, though `edit.paste` selects nothing in a new session's tool.
#[test]
fn edit_copy_after_a_paste_with_the_artboard_tool_replays_on_the_pasted_artboards() {
let mut s = Session::new();
second_artboard_selected(&mut s);
s.execute("edit.copy", &json!({})).unwrap();
s.execute("edit.paste", &json!({})).unwrap();
s.execute("edit.copy", &json!({})).unwrap();
assert_eq!(s.journal.last().unwrap().1, json!({"selectedArtboards": [3], "art": true}));
s.execute("edit.paste", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.artboards.len(), 5);
assert_eq!(documents(&replayed(&s)), documents(&s));
}
/// A recorded action keeps `edit.copy` and `edit.cut` as given, so when it plays they follow the tool
/// chosen then, and a batch step records and leaves out the same values.
#[test]
fn edit_copy_and_cut_with_the_artboard_tool_record_nothing_for_an_action() {
for id in ["edit.copy", "edit.cut"] {
let mut s = Session::new();
second_artboard_selected(&mut s);
let start = second_artboard_selected(&mut s);
s.execute(id, &json!({})).unwrap();
let action = s.journal_for_action(start);
assert_eq!(action, [(id.to_string(), json!({}))], "{id}");
let mut played = Session::new();
played.execute("file.new", &json!({"width": 400, "height": 200, "created": null})).unwrap();
played.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap();
played.execute(id, &action[0].1).unwrap();
assert_eq!(played.doc().unwrap().doc.artboards.len(), 1, "{id}");
assert!(played.clipboard.artboards.is_empty(), "{id}");
assert_eq!(played.clipboard.nodes.len(), 1, "{id}");
let mut s = Session::new();
let start = second_artboard_selected(&mut s);
let steps = json!([{"command": id, "params": {}}, {"command": "edit.paste", "params": {}}]);
s.execute("command.batch", &json!({ "commands": steps })).unwrap();
assert_eq!(s.journal.last().unwrap().1["commands"][0]["params"], json!({"selectedArtboards": [1], "art": true}), "{id}");
assert_eq!(documents(&replayed(&s)), documents(&s), "{id}");
assert_eq!(s.journal_for_action(start)[0].1["commands"][0]["params"], json!({}), "{id}");
}
}
/// Without the Artboard tool, Cut and Copy of objects record nothing more than they did.
#[test]
fn edit_copy_and_cut_of_objects_record_their_params_as_given() {
for id in ["edit.copy", "edit.cut"] {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 200, "created": null})).unwrap();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap();
s.execute(id, &json!({})).unwrap();
assert_eq!(s.journal.last().unwrap(), &(id.to_string(), json!({})), "{id}");
assert!(s.clipboard.artboards.is_empty(), "{id}");
assert_eq!(documents(&replayed(&s)), documents(&s), "{id}");
}
}
/// A recorded `selectedArtboards` needs only a document and is checked as `indices` is, as are `art`
/// and the rule that a cut leaves one artboard. A failed call changes neither the document nor the
/// clipboard.
#[test]
fn edit_copy_and_cut_read_the_recorded_artboards() {
for id in ["edit.copy", "edit.cut"] {
assert!(matches!(Session::new().execute(id, &json!({"selectedArtboards": [0]})), Err(crate::EngineError::Disabled(..))));
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 200, "created": null})).unwrap();
s.execute("artboard.new", &json!({"x": 1000, "y": 0, "width": 300, "height": 100})).unwrap();
s.execute("shape.rectangle", &json!({"x": 1010, "y": 10, "width": 100, "height": 50})).unwrap();
s.execute("select.none", &json!({})).unwrap();
assert!(matches!(s.execute(id, &json!({})), Err(crate::EngineError::Disabled(..))), "{id}");
let before = documents(&s);
for bad in [
json!({"selectedArtboards": [9]}),
json!({"selectedArtboards": []}),
json!({"selectedArtboards": "1"}),
json!({"selectedArtboards": null}),
json!({"selectedArtboards": [1], "art": "yes"}),
] {
let err = s.execute(id, &bad).unwrap_err().to_string();
assert!(err.contains(id) || err.contains("no such artboard"), "{id} {bad}: {err}");
assert_eq!(documents(&s), before, "{id} {bad}");
assert!(s.clipboard.artboards.is_empty(), "{id} {bad}");
}
s.execute(id, &json!({"selectedArtboards": [1], "art": false})).unwrap();
assert_eq!(s.clipboard.artboards.len(), 1, "{id}");
assert!(s.clipboard.nodes.is_empty(), "{id}");
assert_eq!(s.journal.last().unwrap().1, json!({"selectedArtboards": [1], "art": false}), "{id}");
// Objects selected, `art` is still checked.
s.execute("select.all", &json!({})).unwrap();
let err = s.execute(id, &json!({"art": "yes"})).unwrap_err().to_string();
assert!(err.contains(id), "{id}: {err}");
}
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 200, "created": null})).unwrap();
assert!(s.execute("edit.cut", &json!({"selectedArtboards": [0]})).is_err());
assert_eq!(s.doc().unwrap().doc.artboards.len(), 1);
}
/// `artboard.duplicate` and the cut and copy record the tool's Move/Copy Artwork option: replayed in
/// a new session, where the option is on, the art stays behind as it did.
#[test]
fn artboard_commands_record_the_tools_move_art_option() {
for id in ["artboard.duplicate", "artboard.cut", "artboard.copy"] {
for id in ["artboard.duplicate", "artboard.cut", "artboard.copy", "edit.cut", "edit.copy"] {
let mut s = Session::new();
second_artboard_selected(&mut s);
s.set_tool_option("moveArt", &json!(false));