Shapes: Copy, Cut and Paste shape items between shape layers (#227)
Edit > Copy with a shape group (or a path, fill, stroke or path operation) selected in a shape layer's Contents copied the whole layer, and Paste made a new layer. As in After Effects, Copy now copies the selected items, Paste puts them into each selected shape layer's Contents (above its selected item, in that item's group, else on top, with names kept unique there: "Rectangle 2"), and Cut removes them, so Cut + Paste moves them. Pasting with no shape layer selected is an error rather than a new layer. Copying anything else clears the shape item clipboard, as it does the other clipboards. Test: shape_contents_copy_cut_and_paste_between_shape_layers, ctrl_c_and_ctrl_v_copy_a_shape_group_into_another_shape_layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9968950b71
commit
95bb346c89
@@ -1055,3 +1055,59 @@ fn j_k_and_select_all_use_only_the_properties_the_timeline_shows() {
|
||||
assert_eq!(s.state.selected_keys.len(), 1);
|
||||
assert_eq!(s.state.selected_keys[0].prop, op);
|
||||
}
|
||||
|
||||
/// A shape layer's Contents names, top to bottom.
|
||||
fn contents_names(s: &Session, id: u64) -> Vec<String> {
|
||||
layer(s, id).props.sub("contents").unwrap().groups().map(|g| g.name.clone()).collect()
|
||||
}
|
||||
|
||||
/// The uid of the shape item `name` at the top level of a shape layer's Contents.
|
||||
fn contents_item(s: &Session, id: u64, name: &str) -> u64 {
|
||||
layer(s, id).props.sub("contents").unwrap().groups().find(|g| g.name == name).unwrap().uid
|
||||
}
|
||||
|
||||
/// Edit ▸ Copy / Cut / Paste with shape items selected copy the items, not their layer: Paste
|
||||
/// puts them into the selected shape layer, above its selected item or on top, and Cut + Paste
|
||||
/// moves them (#227).
|
||||
#[test]
|
||||
fn shape_contents_copy_cut_and_paste_between_shape_layers() {
|
||||
let mut s = comp();
|
||||
let a = s.execute("layer.newShape", json!({"kind": "rect"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("shape.newShape", json!({"layer": a, "kind": "ellipse"})).unwrap();
|
||||
let b = s.execute("layer.newShape", json!({"kind": "star", "name": "B"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let n = s.active_comp().unwrap().layers.len();
|
||||
// Copy Rectangle 1 of A; paste into B (nothing of B's selected): on top of its Contents.
|
||||
let rect = contents_item(&s, a, "Rectangle 1");
|
||||
s.execute("prop.select", json!({"layer": a, "prop": rect})).unwrap();
|
||||
assert_eq!(s.execute("edit.copy", json!({})).unwrap()["contents"], json!(1));
|
||||
assert!(s.state.clipboard.is_empty(), "not the layer");
|
||||
s.execute("layer.select", json!({"layers": [b]})).unwrap();
|
||||
let r = s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(contents_names(&s, b), ["Rectangle 1", "Polystar 1"]);
|
||||
assert_eq!(s.active_comp().unwrap().layers.len(), n, "no new layer");
|
||||
let pasted = r["contents"][0].as_u64().unwrap();
|
||||
assert_ne!(pasted, rect);
|
||||
assert_eq!(s.state.selected_props, vec![(effectcraft_project::LayerId(b), pasted)]);
|
||||
// Again, with the pasted item selected: above it, with a unique name.
|
||||
s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(contents_names(&s, b), ["Rectangle 2", "Rectangle 1", "Polystar 1"]);
|
||||
s.undo();
|
||||
assert_eq!(contents_names(&s, b), ["Rectangle 1", "Polystar 1"]);
|
||||
assert_eq!(contents_names(&s, a), ["Ellipse 1", "Rectangle 1"], "the original stays");
|
||||
// Cut Ellipse 1 from A and paste it above B's Polystar 1: it moves.
|
||||
s.execute("prop.select", json!({"layer": a, "prop": contents_item(&s, a, "Ellipse 1")})).unwrap();
|
||||
s.execute("edit.cut", json!({})).unwrap();
|
||||
assert_eq!(contents_names(&s, a), ["Rectangle 1"]);
|
||||
assert_eq!(s.active_comp().unwrap().layers.len(), n, "the layer stays");
|
||||
s.execute("prop.select", json!({"layer": b, "prop": contents_item(&s, b, "Polystar 1")})).unwrap();
|
||||
s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(contents_names(&s, b), ["Rectangle 1", "Ellipse 1", "Polystar 1"]);
|
||||
s.undo();
|
||||
s.undo();
|
||||
assert_eq!(contents_names(&s, a), ["Ellipse 1", "Rectangle 1"]);
|
||||
assert_eq!(contents_names(&s, b), ["Rectangle 1", "Polystar 1"]);
|
||||
// Only shape layers take shape items.
|
||||
let sol = solid(&mut s, "#ffffff");
|
||||
s.execute("layer.select", json!({"layers": [sol]})).unwrap();
|
||||
assert!(s.execute("edit.paste", json!({})).is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user