Skip to content

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

Merge pull request #930 from aniliashenko/text-edit-from-timeline

Brandon Thomas0d6adb07bfbb
diff --cc crates/ui-egui/src/panels/timeline.rs
index 50a341ee0,595043538..77916d097
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -1888,16 -1882,12 +1900,12 @@@ pub fn show(app: &mut EffectcraftApp, u
}
}
if row_resp.double_clicked() {
- match &layer.source {
- LayerSource::Comp { item } => actions.push(("comp.open".into(), json!({"comp": item.0}))),
- // Footage and solids open in the Layer panel (paint happens there).
- LayerSource::Footage { .. } | LayerSource::Solid { .. } => {
- actions.push(("layer.openLayer".into(), json!({"layer": layer.id.0})));
- }
- _ => start_rename(&ctx, layer.id.0, &layer.name),
+ match double_click_action(layer) {
+ Some(a) => actions.push(a),
+ None => start_rename(&ctx, layer.id.0, &layer.name),
}
}
- layer_context_menu(&row_resp, layer, &mut actions);
+ layer_context_menu(&row_resp, &comp, layer, &selected, &mut actions);
// Switches.
let sws: [(Icon, bool, &str, bool); 8] = [
(Icon::Shy, sw.shy, "shy", true),
diff --cc crates/ui-egui/tests/ui_text_edit.rs
index 6e16b6762,578f49d04..d3be6a449
--- a/crates/ui-egui/tests/ui_text_edit.rs
+++ b/crates/ui-egui/tests/ui_text_edit.rs
@@@ -409,32 -278,28 +409,58 @@@ fn type_tool_drag_makes_paragraph_text_
assert!(h.state().session.state.text_edit.is_some(), "still editing after resizing");
}
+/// #866: Layer ▸ New ▸ Text (menu or its shortcut) puts an insertion point in the comp, as After
+/// Effects does, so typed keys reach Source Text (and the layer name follows) instead of running
+/// shortcuts while the layer keeps the placeholder "Text".
+#[test]
+fn layer_new_text_menu_and_shortcut_start_typing_into_source_text() {
+ for via_shortcut in [false, true] {
+ let mut s = Session::default();
+ s.execute("comp.new", json!({"name": "Type", "width": 640, "height": 360, "duration": 2})).unwrap();
+ s.execute("layer.newSolid", json!({"color": "#ffffff"})).unwrap();
+ let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_step_dt(1.0 / 60.0).build_eframe(move |_| EffectcraftApp::new(s));
+ h.state_mut().show_panel(PanelKind::Composition);
+ h.run_steps(3);
+ if via_shortcut {
+ key(&mut h, Key::T, Modifiers::COMMAND | Modifiers::ALT | Modifiers::SHIFT);
+ } else {
+ let ctx = h.ctx.clone();
+ effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "layer.newText", json!({})).unwrap();
+ h.run_steps(2);
+ }
+ let (lid, text, _, _) = edited(&h);
+ assert_eq!(text, "", "no placeholder to type over (shortcut: {via_shortcut})");
+ type_text(&mut h, "My First Project");
+ key(&mut h, Key::Escape, Modifiers::NONE);
+ assert!(h.state().session.state.text_edit.is_none(), "Escape commits");
+ let s = &h.state().session;
+ assert_eq!(layer_doc(s, LayerId(lid)).unwrap().text, "My First Project", "typed text is the Source Text");
+ assert_eq!(s.active_comp().unwrap().layer(LayerId(lid)).unwrap().name, "My First Project", "the name follows the text");
+ }
+}
++
+ /// Double-clicking a text layer in the Timeline, on its name or on its bar, edits its text in the
+ /// Composition viewer with the whole text selected, as in After Effects (Enter renames).
+ #[test]
+ fn timeline_double_click_on_a_text_layer_edits_its_text() {
+ for target in ["row", "bar"] {
+ let mut s = Session::default();
+ s.execute("comp.new", json!({"name": "Type", "width": 640, "height": 360, "duration": 2})).unwrap();
+ let lid = s.execute("layer.newText", json!({"text": "alpha beta"})).unwrap()["layer"].as_u64().unwrap();
+ let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_step_dt(1.0 / 60.0).build_eframe(move |_| EffectcraftApp::new(s));
+ h.state_mut().show_panel(PanelKind::Composition);
+ h.run_steps(3);
+ let p = rect(&h, &format!("timeline.layer.{lid}.{target}")).center();
+ click(&mut h, p, Modifiers::NONE);
+ click(&mut h, p, Modifiers::NONE);
+ let (layer, text, anchor, caret) = edited(&h);
+ assert_eq!(layer, lid, "{target}");
+ assert_eq!((anchor.min(caret), anchor.max(caret)), (0, 10), "everything selected ({target})");
+ assert!(h.state().auto.find(&format!("timeline.layer.{lid}.nameEdit")).is_none(), "no rename field ({target})");
+ assert_eq!(text, "alpha beta");
+ type_text(&mut h, "gamma");
+ key(&mut h, Key::Escape, Modifiers::NONE);
+ assert!(h.state().session.state.text_edit.is_none(), "Escape commits ({target})");
+ assert_eq!(layer_doc(&h.state().session, LayerId(lid)).unwrap().text, "gamma", "typing replaced the text ({target})");
+ }
+ }