FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#914: one undo step for a multi-point Trim by Frames.
Vikram Bhaskaran361ba9d58ce6
diff --git a/crates/engine/src/trim.rs b/crates/engine/src/trim.rsindex 951a873c8..7c004b2b8 100644--- a/crates/engine/src/trim.rs+++ b/crates/engine/src/trim.rs@@ -171,7 +171,9 @@ pub fn toggle_type(s: &mut Session) -> Result<Value> {/// Trim every selected edit point by `delta` (edit point movement; positive = later).fn trim_all(s: &mut Session, delta: Tick) -> Result<Value> {+ let n0 = s.history.undo.len();let applied = trim_all_raw(s, &|_, _| Some(delta))?;+ crate::clip_ops::collapse_history(s, n0, "Trim by Frames");let first = applied.first().and_then(Value::as_i64).map(Tick).unwrap_or_default();add_shift(s, first);Ok(json!({"applied": applied}))@@ -230,7 +232,9 @@ pub fn nudge(s: &mut Session, p: &Value) -> Result<Value> {/// `trim.extendToPlayhead`: move each selected edit point to the playhead.pub fn extend_to_playhead(s: &mut Session) -> Result<Value> {let ph = s.playhead();+ let n0 = s.history.undo.len();let applied = trim_all_raw(s, &|seq, e| edit_time(seq, e).map(|t| ph - t))?;+ crate::clip_ops::collapse_history(s, n0, "Extend Edit to Playhead");let first = applied.first().and_then(Value::as_i64).map(Tick).unwrap_or_default();add_shift(s, first);Ok(json!({"applied": applied}))@@ -343,6 +347,7 @@ pub fn monitor_info(s: &Session) -> Value {/// default video/audio transition at every selected edit point.pub fn apply_default_transitions(s: &mut Session) -> Result<Value> {let pts = s.state.edit_points.clone();+ let n0 = s.history.undo.len();let mut ids = Vec::new();for ep in &pts {let seq = s.active_sequence().ok_or(EngineError::NoSequence)?;@@ -356,6 +361,7 @@ pub fn apply_default_transitions(s: &mut Session) -> Result<Value> {if ids.is_empty() {return Err(EngineError::Other("no transition could be applied at the selected edit points".into()));}+ crate::clip_ops::collapse_history(s, n0, "Apply Default Transitions");Ok(json!({"transitions": ids}))}diff --git a/crates/engine/src/trim_tests.rs b/crates/engine/src/trim_tests.rsindex b003e48dd..cb3d32ccd 100644--- a/crates/engine/src/trim_tests.rs+++ b/crates/engine/src/trim_tests.rs@@ -237,6 +237,34 @@ fn extend_to_playhead_moves_each_unequal_out_point_to_the_playhead() {assert_eq!(q.find_item(b).unwrap().1.end(), ph);}+/// #914: Trim by Frames on two selected edit points is one undo (and redo) step.+#[test]+fn multipoint_trim_by_frames_is_one_undo_step() {+ let mut s = demo();+ s.execute("sequence.linkedSelection", json!({"on": false})).unwrap();+ let c = v1(&s);+ let (a, b) = (c[0], c[1]);+ s.execute("trim.selectEditPoint", json!({"clip": a.0, "edge": "out", "kind": "trim"})).unwrap();+ s.execute("trim.selectEditPoint", json!({"clip": b.0, "edge": "out", "kind": "trim", "add": true})).unwrap();+ let undo0 = s.history.undo.len();+ let d = s.sequence_rate().tick_of(-1);+ s.execute("trim.nudge", json!({"frames": -1})).unwrap();+ let q = s.active_sequence().unwrap();+ let a1 = q.find_item(ClipId(a.0)).unwrap().1.end();+ let b1 = q.find_item(ClipId(b.0)).unwrap().1.end();+ assert_eq!(a1, a.2 + d);+ assert_eq!(b1, b.2 + d);+ assert_eq!(s.history.undo.len(), undo0 + 1, "one undo step for both clips");+ s.execute("edit.undo", json!({})).unwrap();+ let q = s.active_sequence().unwrap();+ assert_eq!(q.find_item(ClipId(a.0)).unwrap().1.end(), a.2);+ assert_eq!(q.find_item(ClipId(b.0)).unwrap().1.end(), b.2);+ s.execute("edit.redo", json!({})).unwrap();+ let q = s.active_sequence().unwrap();+ assert_eq!(q.find_item(ClipId(a.0)).unwrap().1.end(), a1);+ assert_eq!(q.find_item(ClipId(b.0)).unwrap().1.end(), b1);+}+/// #653: the delta the Timeline previews while an edge is dragged is the one `timeline.trim`/// applies on release: dragging the last clip's Out edge far past the end of its media stops at/// the media's end instead of following the pointer.