From 5d27d1377cb2ad6ebcc6c8719f1ac9127b0983ef Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 18 Nov 2026 16:21:47 +0100 Subject: [PATCH 1/2] #3901: pasted Source Text keyframes keep their style Pasting a copied Source Text keyframe (keys.paste, Paste Reversed) or a copied unanimated Source Text value (Edit > Copy / Paste) went through the value's JSON form, which is the characters only, so the pasted key took the font, size and colours of the property's current value. A copied text value now pastes as the whole document; every other kind is pasted as before. --- crates/engine/src/cmd/anim.rs | 13 ++++- crates/engine/src/cmd/edit.rs | 2 +- crates/engine/src/tests/timeline.rs | 81 +++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/anim.rs b/crates/engine/src/cmd/anim.rs index e23fc736f..c11aefeb4 100644 --- a/crates/engine/src/cmd/anim.rs +++ b/crates/engine/src/cmd/anim.rs @@ -56,6 +56,17 @@ fn compatible(a: &Property, b: &effectcraft_keyframe::Value) -> bool { a.value.kind_name() == b.kind_name() && a.value.components().len() == b.components().len() } +/// A copied value (keyframe or unanimated property) shaped for the property `target` it is pasted +/// into. A copied Source Text keeps its whole document, characters and style, as in After Effects +/// (#3901): its JSON form is the characters only, so going through it would take the font, size +/// and colours from the target's current value. Every other kind goes through the JSON form. +pub(super) fn pasted_value(target: &KValue, copied: &KValue) -> Option { + match (target, copied) { + (KValue::Text(_), KValue::Text(_)) => Some(copied.clone()), + _ => target.coerce_json(&copied.to_json()), + } +} + pub(crate) fn locked_selection(comp: &effectcraft_project::Comp, selected: &[KeyRef]) -> Vec { selected.iter().filter(|k| comp.layer(k.layer).is_some_and(|l| l.switches.locked)).copied().collect() } @@ -131,7 +142,7 @@ fn paste(s: &mut Session, p: &Value) -> Result { for (k, lt) in clip[*ci].keys.iter().zip(times) { let mut k = k.clone(); k.time = lt; - if let Some(v) = pr.value.coerce_json(&k.value.to_json()) { + if let Some(v) = pasted_value(&pr.value, &k.value) { k.value = v; } if pr.hold_only { diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index c2ecb838d..8cba6a2ce 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -423,7 +423,7 @@ fn paste_properties(s: &mut Session, p: &Value) -> Result { for (path, v) in &values { let path = super::resolve_effect_path(l, path); if let Some(pr) = l.props.prop_mut(&path) - && let Some(v) = pr.value.coerce_json(&v.to_json()) + && let Some(v) = super::anim::pasted_value(&pr.value, v) { pr.set_value_at(lt, v); n += 1; diff --git a/crates/engine/src/tests/timeline.rs b/crates/engine/src/tests/timeline.rs index f0996f4af..89fc598b4 100644 --- a/crates/engine/src/tests/timeline.rs +++ b/crates/engine/src/tests/timeline.rs @@ -1664,3 +1664,84 @@ fn convert_expression_to_keyframes_refuses_a_zero_frame_duration() { assert!(e.contains("frame duration"), "{e}"); assert!(prop(&s, l, "transform/rotation").keys.is_empty()); } + +/// Source Text of text layer `t`, its static value set to `doc` (no keyframes touched). +fn set_static_text(s: &mut Session, t: u64, doc: &effectcraft_keyframe::TextDoc) { + let cid = s.active_comp_id().unwrap(); + let comp = std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap(); + comp.layer_mut(effectcraft_project::LayerId(t)).unwrap().props.prop_mut("text/sourceText").unwrap().value = KV::Text(Box::new(doc.clone())); +} + +/// A text layer's current Source Text document, restyled: `text` in fill `fill`, size `size`. +fn styled_text(s: &Session, t: u64, text: &str, fill: [f32; 4], size: f64) -> effectcraft_keyframe::TextDoc { + let mut doc = prop(s, t, "text/sourceText").value.as_text().unwrap().clone(); + doc.text = text.into(); + doc.fill = fill; + doc.size = size; + doc +} + +/// #3901: a pasted Source Text keyframe is the copied one, characters and style, not the copied +/// characters in the property's current style. +#[test] +fn pasted_source_text_key_keeps_its_style() { + let (mut s, _) = setup(); + let t = s.execute("layer.newText", json!({"text": "Start", "size": 40})).unwrap()["layer"].as_u64().unwrap(); + let red = styled_text(&s, t, "Red", [1.0, 0.0, 0.0, 1.0], 72.0); + let blue = styled_text(&s, t, "Blue", [0.0, 0.0, 1.0, 1.0], 30.0); + animate(&mut s, t, "text/sourceText", &[(0.0, serde_json::to_value(&red).unwrap()), (1.0, serde_json::to_value(&blue).unwrap())]); + set_static_text(&mut s, t, &blue); + let copied = prop(&s, t, "text/sourceText").keys[0].value.clone(); + assert_eq!(copied.as_text().map(|d| d.fill), Some(red.fill), "key A is red"); + assert_ne!(prop(&s, t, "text/sourceText").value.as_text().map(|d| d.fill), Some(red.fill), "the property's own value is not red"); + let uid = prop(&s, t, "text/sourceText").uid; + s.execute("keys.select", json!({"keys": [{"layer": t, "prop": uid, "time": 0.0}]})).unwrap(); + assert_eq!(s.execute("keys.copy", json!({})).unwrap(), json!(1)); + assert_eq!(s.execute("keys.paste", json!({"layers": [t], "time": 2.0})).unwrap(), json!(1)); + let p = prop(&s, t, "text/sourceText"); + assert_eq!(p.keys.len(), 3); + let pasted = p.keys[2].value.as_text().unwrap(); + assert_eq!((pasted.text.as_str(), pasted.fill, pasted.size), ("Red", red.fill, 72.0), "text, fill and size travel with the key"); + assert_eq!(p.keys[2].value, copied, "the whole document travels with the key"); + // Edit ▸ Paste Reversed goes the same way. + s.execute("keys.select", json!({"keys": [{"layer": t, "prop": uid, "time": 0.0}]})).unwrap(); + s.execute("keys.copy", json!({})).unwrap(); + s.execute("time.set", json!({"time": 3.0})).unwrap(); + s.execute("edit.pasteReversedKeyframes", json!({"layers": [t]})).unwrap(); + let p = prop(&s, t, "text/sourceText"); + assert_eq!(p.keys.last().map(|k| &k.value), Some(&copied)); +} + +/// #3901: Edit ▸ Copy of an unanimated Source Text and Edit ▸ Paste onto another text layer +/// gives that layer the copied document, style included. +#[test] +fn pasted_source_text_value_keeps_its_style() { + let (mut s, _) = setup(); + let a = s.execute("layer.newText", json!({"text": "Red", "size": 40})).unwrap()["layer"].as_u64().unwrap(); + let b = s.execute("layer.newText", json!({"text": "Blue", "size": 40})).unwrap()["layer"].as_u64().unwrap(); + let red = styled_text(&s, a, "Red", [1.0, 0.0, 0.0, 1.0], 72.0); + let blue = styled_text(&s, b, "Blue", [0.0, 0.0, 1.0, 1.0], 30.0); + set_static_text(&mut s, a, &red); + set_static_text(&mut s, b, &blue); + s.execute("layer.select", json!({"layers": [a]})).unwrap(); + s.execute("prop.select", json!({"layer": a, "path": "text/sourceText", "selectKeys": false})).unwrap(); + s.execute("edit.copy", json!({})).unwrap(); + assert_eq!(s.state.value_clipboard.len(), 1); + s.execute("layer.select", json!({"layers": [b]})).unwrap(); + s.execute("edit.paste", json!({})).unwrap(); + assert_eq!(prop(&s, b, "text/sourceText").value, KV::Text(Box::new(red)), "layer B gets the copied text and style"); +} + +/// Typing plain characters into Source Text (control channel / scripts) still keeps the +/// property's style: the JSON form of a text value stays its characters (not changed by #3901). +#[test] +fn plain_string_source_text_keeps_the_current_style() { + let (mut s, _) = setup(); + let t = s.execute("layer.newText", json!({"text": "Start", "size": 40})).unwrap()["layer"].as_u64().unwrap(); + let blue = styled_text(&s, t, "Start", [0.0, 0.0, 1.0, 1.0], 30.0); + set_static_text(&mut s, t, &blue); + s.execute("prop.addKey", json!({"layer": t, "path": "text/sourceText", "time": 0.0, "value": "Hello"})).unwrap(); + let k = prop(&s, t, "text/sourceText").keys[0].value.as_text().unwrap().clone(); + assert_eq!((k.text.as_str(), k.fill, k.size), ("Hello", blue.fill, 30.0)); + assert_eq!(s.execute("prop.get", json!({"layer": t, "path": "text/sourceText"})).unwrap()["value"], json!("Hello")); +} From 6619dbe1d49b48d0278e6268f908ab9b3015240c Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 18 Nov 2026 17:40:33 +0100 Subject: [PATCH 2/2] #3901: the Paste Reversed check counts the keys and checks the reversed key's time and value --- crates/engine/src/tests/timeline.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/tests/timeline.rs b/crates/engine/src/tests/timeline.rs index 89fc598b4..281438771 100644 --- a/crates/engine/src/tests/timeline.rs +++ b/crates/engine/src/tests/timeline.rs @@ -1709,7 +1709,9 @@ fn pasted_source_text_key_keeps_its_style() { s.execute("time.set", json!({"time": 3.0})).unwrap(); s.execute("edit.pasteReversedKeyframes", json!({"layers": [t]})).unwrap(); let p = prop(&s, t, "text/sourceText"); - assert_eq!(p.keys.last().map(|k| &k.value), Some(&copied)); + assert_eq!(p.keys.len(), 4, "Paste Reversed adds one key"); + assert!((p.keys[3].time.seconds() - 3.0).abs() < 1e-6, "the reversed key is at 3 s: {}", p.keys[3].time.seconds()); + assert_eq!(p.keys[3].value, copied, "the reversed key keeps the whole document"); } /// #3901: Edit ▸ Copy of an unanimated Source Text and Edit ▸ Paste onto another text layer