Edit: Copy with a property selected copies that property, and Paste sets it on the selected layers (#493)
Cause: edit.copy handled text editing, selected keyframes, effects and shape items, then fell back to copying the selected layers. Selecting a property selects its keys, so an animated property copied, but an unanimated one (or the Transform group, whose keys prop.select doesn't select) copied the whole layer, and Paste added a duplicate layer instead of setting the property. Fix: with properties (or the Transform group) selected, Edit > Copy copies, as After Effects does, each animated property's keys (the selected ones, else all of them, through keys.copy) and each unanimated property's value into a new value clipboard keyed by match path. Edit > Paste sets those values on the same properties of the selected layers (a key at the CTI where the target is animated) and pastes the keys at the CTI, as one undo step (keys.paste now honours `merge`). Keys alone still answer with their count, as before. Test: copy_a_selected_property_pastes_onto_the_same_property (static Position, then the Transform group with animated Opacity: values and keys land on layer B, no layer is added, one undo step each). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QiAJeFttZp83Fh7YuzAR5f (cherry picked from commit 8267519ebe20e889196e538de23b85b04a1fa76a)
This commit is contained in:
@@ -346,6 +346,53 @@ fn keyframe_clipboard_paste_and_paste_reversed() {
|
||||
assert_eq!((keys[0].value.as_f64(), keys[1].value.as_f64()), (0.0, 100.0));
|
||||
}
|
||||
|
||||
/// #493: Edit ▸ Copy with a property selected copies that property (its value when it isn't
|
||||
/// animated, its keys when it is), and Paste sets the same property of the selected layer, as
|
||||
/// in After Effects, instead of copying the whole layer.
|
||||
#[test]
|
||||
fn copy_a_selected_property_pastes_onto_the_same_property() {
|
||||
let mut s = comp();
|
||||
let a = solid(&mut s, "#ff0000");
|
||||
let b = solid(&mut s, "#00ff00");
|
||||
let n_layers = s.active_comp().unwrap().layers.len();
|
||||
s.execute("prop.set", json!({"layer": a, "path": "transform/position", "value": [10, 20]})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": a, "path": "transform/rotation", "value": 30})).unwrap();
|
||||
s.execute("prop.select", json!({"layer": a, "path": "transform/position"})).unwrap();
|
||||
s.execute("edit.copy", json!({})).unwrap();
|
||||
assert!(s.state.clipboard.is_empty(), "the layer isn't copied");
|
||||
s.execute("layer.select", json!({"layers": [b]})).unwrap();
|
||||
let undo = s.history.undo.len();
|
||||
s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(s.active_comp().unwrap().layers.len(), n_layers);
|
||||
assert_eq!(layer(&s, b).props.prop("transform/position").unwrap().value.as_vec3()[..2], [10.0, 20.0]);
|
||||
assert_eq!(layer(&s, b).props.prop("transform/rotation").unwrap().value.as_f64(), 0.0, "only the copied property");
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert_ne!(layer(&s, b).props.prop("transform/position").unwrap().value.as_vec3()[..2], [10.0, 20.0]);
|
||||
assert_eq!(s.history.undo.len(), undo);
|
||||
// The Transform group with an animated Opacity: its keys (at the CTI) and the other values,
|
||||
// in one undo step.
|
||||
s.execute("prop.toggleAnimation", json!({"layer": a, "path": "transform/opacity"})).unwrap();
|
||||
s.execute("time.set", json!({"time": 1.0})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": a, "path": "transform/opacity", "value": 0})).unwrap();
|
||||
let transform = layer(&s, a).props.sub("transform").unwrap().uid;
|
||||
s.execute("prop.select", json!({"layer": a, "prop": transform})).unwrap();
|
||||
s.execute("edit.copy", json!({})).unwrap();
|
||||
s.execute("layer.select", json!({"layers": [b]})).unwrap();
|
||||
s.execute("time.set", json!({"time": 2.0})).unwrap();
|
||||
let undo = s.history.undo.len();
|
||||
s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(s.history.undo.len(), undo + 1);
|
||||
let l = layer(&s, b);
|
||||
let keys = &l.props.prop("transform/opacity").unwrap().keys;
|
||||
assert_eq!(keys.len(), 2);
|
||||
assert!((keys[0].time.seconds() - 2.0).abs() < 1e-6 && keys[1].value.as_f64() == 0.0);
|
||||
assert_eq!(l.props.prop("transform/rotation").unwrap().value.as_f64(), 30.0);
|
||||
assert_eq!(s.active_comp().unwrap().layers.len(), n_layers);
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
let l = layer(&s, b);
|
||||
assert!(l.props.prop("transform/opacity").unwrap().keys.is_empty() && l.props.prop("transform/rotation").unwrap().value.as_f64() == 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn property_links_and_expression_only() {
|
||||
let mut s = comp();
|
||||
|
||||
Reference in New Issue
Block a user