Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Refuse timeline.move when the clip's source track is locked.

Vikram Bhaskarand79248489b90
diff --git a/crates/edit/src/lib.rs b/crates/edit/src/lib.rs
index bb4e6415b..3f059c253 100644
--- a/crates/edit/src/lib.rs
+++ b/crates/edit/src/lib.rs
@@ -503,7 +503,10 @@ pub fn move_items(seq: &mut Sequence, moves: &[(ClipId, TrackId, Tick)], insert_
let mut work = seq.clone();
let mut placed = Vec::new();
for (c, dest, start) in moves {
- let (_, it) = work.find_item(*c).ok_or(EditError::NoItem(*c))?;
+ let (src, it) = work.find_item(*c).ok_or(EditError::NoItem(*c))?;
+ if work.track(src).is_some_and(|t| t.locked) {
+ return Err(EditError::Locked);
+ }
let mut it = it.clone();
if work.track(*dest).ok_or(EditError::NoTrack(*dest))?.locked {
return Err(EditError::Locked);
diff --git a/crates/engine/src/timeline_move_tests.rs b/crates/engine/src/timeline_move_tests.rs
index 6f176b814..565edd55b 100644
--- a/crates/engine/src/timeline_move_tests.rs
+++ b/crates/engine/src/timeline_move_tests.rs
@@ -100,6 +100,23 @@ fn a_linked_partner_on_a_locked_track_stays_and_the_listed_clip_still_moves() {
assert_eq!(*s.project, *before);
}
+/// Moving a clip off a locked track used to leave it there and place another item with the same
+/// clip id on the destination (#917). The source is locked, so the move is refused.
+#[test]
+fn a_clip_on_a_locked_track_cannot_move_to_another_track() {
+ let mut s = demo();
+ let (v_track, v, _, _) = pair_in_an_empty_sequence(&mut s, 0.0);
+ s.execute("timeline.setTrack", json!({"track": "V1", "locked": true})).unwrap();
+ let before = s.project.clone();
+ let e = s.execute("timeline.move", json!({"moves": [{"clip": v.id.0, "track": "V2", "time": v.start.0}], "linked": false})).unwrap_err();
+ assert!(matches!(&e, EngineError::Edit(filmcraft_edit::EditError::Locked)), "{e:?}");
+ assert_eq!(*s.project, *before);
+ let q = s.active_sequence().unwrap();
+ assert_eq!(q.find_item(v.id).map(|(t, _)| t), Some(v_track));
+ assert_eq!(q.video_tracks[1].items.len(), 0);
+ q.check().unwrap();
+}
+
/// A partner that would land where it already is does not move: re-placing it would drop the
/// transitions at its edges and list it in `moved` for nothing. Moving only the picture to
/// another track at the same time leaves the sound as it was.