Skip to content

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

fix: View > Go to Time accepts the dialog's float frame [skip ci]

pravdomilc8968cee1f22
diff --git a/crates/engine/src/commands/time.rs b/crates/engine/src/commands/time.rs
index f98ea5edb..17f349355 100644
--- a/crates/engine/src/commands/time.rs
+++ b/crates/engine/src/commands/time.rs
@@ -61,8 +61,9 @@ pub fn parse_display_time(s: &Session, comp: &Comp, text: &str, current: i64) ->
fn set(s: &mut Session, p: &Value) -> Result<Value> {
let comp = s.active_comp().ok_or(EngineError::NoComp)?;
- let t = if let Some(f) = p.get("frame").and_then(Value::as_i64) {
- comp.frame_rate.tick_of(f)
+ // Dialog number fields send floats (`5.0`), so a frame is any JSON number, rounded.
+ let t = if let Some(f) = f_p(p, "frame") {
+ comp.frame_rate.tick_of(f.round() as i64)
} else if let Some(tc) = str_p(p, "timecode") {
let cur = comp.frame_rate.frame_at(s.time());
let f = parse_display_time(s, comp, tc, cur).map_err(|e| super::bad("time.set", e))?;
diff --git a/crates/engine/src/tests_timeline.rs b/crates/engine/src/tests_timeline.rs
index 6a74a23b3..74d42221f 100644
--- a/crates/engine/src/tests_timeline.rs
+++ b/crates/engine/src/tests_timeline.rs
@@ -883,3 +883,14 @@ fn property_edits_apply_to_every_selected_layer() {
s.execute("prop.set", json!({"layer": a, "path": "transform/rotation", "value": 30})).unwrap();
assert_eq!(prop(&s, b, "transform/rotation").value.as_f64(), 0.0);
}
+
+/// View > Go to Time's dialog sends its Frame field as a float; `time.set` used to reject it
+/// with "need `time`, `frame` or `timecode`".
+#[test]
+fn go_to_time_accepts_a_float_frame_from_the_dialog() {
+ let (mut s, _) = setup();
+ let r = s.execute("time.set", json!({"frame": 12.0})).unwrap();
+ assert_eq!(r["frame"], json!(12));
+ let r = s.execute("time.set", json!({"frame": 7})).unwrap();
+ assert_eq!(r["frame"], json!(7));
+}