Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Clipboard: Copy puts keyframe text on the system clipboard (#1908)

tylerjenningsw40d5466cc503
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 92893dcb6..38967187d 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -853,10 +853,15 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
const COPY_COMMANDS: &[&str] =
&["edit.copy", "edit.cut", "edit.copyWithPropertyLinks", "edit.copyWithRelativePropertyLinks", "edit.copyExpressionOnly", "keys.copy", "effect.copy"];
-/// A line for the system clipboard naming what EffectCraft copied. The system clipboard must
-/// hold something: with nothing on it, the windowing layer sends no paste event for Ctrl+V.
-fn clipboard_note(s: &effectcraft_engine::Session) -> String {
+/// Text for the system clipboard: copied keyframes and values as After Effects keyframe text,
+/// for other applications (#1908), else a line naming what EffectCraft copied. The system
+/// clipboard must hold something: with nothing on it, the windowing layer sends no paste event
+/// for Ctrl+V. Paste in EffectCraft uses its own clipboard either way.
+fn clipboard_text(s: &effectcraft_engine::Session) -> String {
let st = &s.state;
+ if let Some(text) = &st.keyframe_text {
+ return text.clone();
+ }
let n = |n: usize, one: &str, many: &str| format!("EffectCraft: {n} {}", if n == 1 { one } else { many });
if st.clip_is_keys && !st.key_clipboard.is_empty() {
n(st.key_clipboard.iter().map(|c| c.keys.len()).sum(), "keyframe", "keyframes")
@@ -878,7 +883,7 @@ pub(crate) fn run_engine(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str
if let Err(e) = &r {
app.ui.status = e.clone();
} else if COPY_COMMANDS.contains(&id) && app.session.state.text_edit.is_none() {
- ctx.copy_text(clipboard_note(&app.session));
+ ctx.copy_text(clipboard_text(&app.session));
}
let events = app.session.drain_events();
for (index, ev) in events.into_iter().enumerate() {
diff --git a/crates/ui-egui/tests/ui_keyframes.rs b/crates/ui-egui/tests/ui_keyframes.rs
index b47963d85..2eebb068f 100644
--- a/crates/ui-egui/tests/ui_keyframes.rs
+++ b/crates/ui-egui/tests/ui_keyframes.rs
@@ -105,11 +105,15 @@ fn ctrl_c_and_ctrl_v_copy_and_paste_keys_at_the_current_time() {
_ => None,
})
.collect();
- assert_eq!(copied, ["EffectCraft: 1 keyframe"], "the system clipboard is filled, so Ctrl+V sends a paste event");
+ // The system clipboard has the key as After Effects keyframe text (for other applications),
+ // so it isn't empty and Ctrl+V sends a paste event.
+ let [text] = copied.as_slice() else { panic!("one copy: {copied:?}") };
+ assert!(text.starts_with("Adobe After Effects 8.0 Keyframe Data\n"), "{text}");
+ assert!(text.contains("Transform\tOpacity\n\tFrame\tpercent\n\t30\t100\n"), "{text}");
assert!(h.state().session.state.clip_is_keys);
// Move to 3 s, Ctrl+V: the key lands there.
h.state_mut().session.set_time(effectcraft_engine::time::Tick::from_seconds_f64(3.0));
- h.input_mut().events.push(Event::Paste("EffectCraft: 1 keyframe".into()));
+ h.input_mut().events.push(Event::Paste(text.clone()));
h.run_steps(2);
assert_eq!(key_times(&h, id), vec![0.0, 1.0, 3.0]);
}
@@ -190,8 +194,18 @@ fn copy_and_paste_key_subsets_across_position_rotation_and_scale() {
assert_eq!(h.state().session.state.selected_props.len(), 3);
h.input_mut().events.push(Event::Copy);
h.step();
- let note = format!("EffectCraft: {count} keyframes");
- assert!(h.output().platform_output.commands.iter().any(|command| matches!(command, egui::OutputCommand::CopyText(text) if text == &note)));
+ let note = h
+ .output()
+ .platform_output
+ .commands
+ .iter()
+ .find_map(|command| match command {
+ egui::OutputCommand::CopyText(text) => Some(text.clone()),
+ _ => None,
+ })
+ .unwrap();
+ let rows = note.lines().filter(|line| line.strip_prefix('\t').is_some_and(|row| row.starts_with(|c: char| c.is_ascii_digit()))).count();
+ assert_eq!(rows, count, "one row per copied key: {note}");
h.state_mut().session.set_time(effectcraft_engine::time::Tick::from_seconds_f64(2.0));
let undo_steps = h.state().session.history.undo.len();
h.input_mut().events.push(Event::Paste(note));