FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
edit: reject repeated clip identities in move plans
Earl Cob474ca6ca488
diff --git a/AGENTS.md b/AGENTS.mdindex 0683cb87a..b808459e8 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -124,6 +124,14 @@ See [§0](#0-never-crash). It outranks every other engineering rule.### 3.2 The rest+**Invariant — move identity uniqueness:** A move plan lists each clip identity at most once.+The core move operation rejects repeated ids before mutation or id allocation; placing one identity+on multiple tracks makes selection and later identity-based editing ambiguous. Copies receive new ids+and retain each entry's requested destination. Destination track creation and the edit commit together.+In an idle session, a rejected duplicate move retains the project and its undo and redo history.+Selection-derived edit plans keep each identity once in first-occurrence order before expanding+linked partners; explicit move requests with repeated identities are still rejected.+See `CLAUDE.md`: pure Rust, dependency layering (`cargo xtask layers`), exact `Tick` time, everything isa command, everything is agent-drivable, and the quality gates (`cargo xtask ci`) before every commit.diff --git a/crates/edit/src/lib.rs b/crates/edit/src/lib.rsindex 2f2588d6c..5478030f0 100644--- a/crates/edit/src/lib.rs+++ b/crates/edit/src/lib.rs@@ -509,6 +509,12 @@ pub fn close_gap(seq: &mut Sequence, track: TrackId, t: Tick) -> Result<()> {/// Move items by (track, time) offsets with overwrite (default drag) or insert (Cmd-drag) semantics./// `moves`: (item, destination track, new start).pub fn move_items(seq: &mut Sequence, moves: &[(ClipId, TrackId, Tick)], insert_mode: bool, ctx: &mut EditCtx) -> Result<()> {+ let mut seen = std::collections::HashSet::new();+ for (clip, _, _) in moves {+ if !seen.insert(*clip) {+ return Err(EditError::Other(format!("clip {} is listed more than once in this move", clip.0)));+ }+ }let mut work = seq.clone();let mut placed = Vec::new();for (c, dest, start) in moves {diff --git a/crates/edit/src/tests.rs b/crates/edit/src/tests.rsindex 9b42c106a..78b9dfaca 100644--- a/crates/edit/src/tests.rs+++ b/crates/edit/src/tests.rs@@ -77,6 +77,21 @@ impl Fx {}}+#[test]+fn move_rejects_repeated_clip_ids_without_mutation() {+ for insert_mode in [false, true] {+ let mut fx = Fx::new();+ let (v1, v2) = (fx.v(0), fx.v(1));+ let c = fx.put(v1, 0, 10, 0);+ let before = fx.seq.clone();+ let mut n = fx.next;+ let result = move_items(&mut fx.seq, &[(c, v1, f(20)), (c, v2, f(20))], insert_mode, &mut Fx::ctx(&mut n));+ assert!(result.is_err(), "moving one identity to two tracks must be rejected: {result:?}");+ assert_eq!(fx.seq, before);+ assert_eq!(n, fx.next, "a rejected move consumes no ids");+ }+}+#[test]fn overwrite_splits_underlying() {let mut fx = Fx::new();diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rsindex c99e5c64b..43c5ef401 100644--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@ -344,10 +344,10 @@ pub(crate) fn item_p(p: &Value, k: &str) -> Option<ItemId> {/// as `copied`.fn move_clips(s: &mut Session, p: &Value) -> Result<Value> {const CMD: &str = "timeline.move";- let mut listed: Vec<(ClipId, TrackId, Tick)> = Vec::new();- let mut new_moves = Vec::new();+ let mut listed: Vec<(ClipId, TrackId, Tick, bool)> = Vec::new();for m in p.get("moves").and_then(Value::as_array).into_iter().flatten() {- let track = if str_p(m, "track").is_some_and(|t| t.eq_ignore_ascii_case("new")) {+ let new_track = str_p(m, "track").is_some_and(|t| t.eq_ignore_ascii_case("new"));+ let track = if new_track {let clip = clip_p(m, "clip").ok_or_else(|| bad(CMD, "new track needs a clip"))?;let q = s.active_sequence().ok_or(EngineError::NoSequence)?;let (source, _) = q.find_item(clip).ok_or(edit::EditError::NoItem(clip))?;@@ -357,13 +357,12 @@ fn move_clips(s: &mut Session, p: &Value) -> Result<Value> {if m.get("time").and_then(Value::as_i64).is_none() {return Err(bad(CMD, "new track needs a time"));}- new_moves.push((clip, source));Some(source)} else {track_p(s, m, "track", CMD)?};if let (Some(clip), Some(track), Some(time)) = (clip_p(m, "clip"), track, m.get("time").and_then(Value::as_i64)) {- listed.push((clip, track, Tick(time)));+ listed.push((clip, track, Tick(time), new_track));}}if listed.is_empty() {@@ -371,32 +370,32 @@ fn move_clips(s: &mut Session, p: &Value) -> Result<Value> {}let follow = bool_p(p, "linked").unwrap_or(s.state.linked_selection);let q = s.active_sequence().ok_or(EngineError::NoSequence)?;- // (clip, destination track, new start, where a partner starts now). `time` is any i64: the- // sums are done in i128, where a few i64 values cannot overflow, and checked on the way back.- let mut plan: Vec<(ClipId, TrackId, i128, Option<i128>)> = Vec::new();- for &(clip, track, time) in &listed {- plan.push((clip, track, i128::from(time.0), None));+ // (clip, destination track, new start, where a partner starts now, new track requested).+ // `time` is any i64: sums use i128 and are checked on the way back.+ let mut plan: Vec<(ClipId, TrackId, i128, Option<i128>, bool)> = Vec::new();+ for &(clip, track, time, new_track) in &listed {+ plan.push((clip, track, i128::from(time.0), None, new_track));let Some((_, it)) = q.find_item(clip) else { continue }; // `edit::move_items` reports itlet Some(link) = it.link.filter(|_| follow) else { continue };let offset = i128::from(time.0) - i128::from(it.start.0);for t in q.all_tracks().filter(|t| !t.locked) {for partner in t.items.iter().filter(|i| i.link == Some(link)) {if !listed.iter().any(|m| m.0 == partner.id) && !plan.iter().any(|m| m.0 == partner.id) {- plan.push((partner.id, t.id, i128::from(partner.start.0) + offset, Some(i128::from(partner.start.0))));+ plan.push((partner.id, t.id, i128::from(partner.start.0) + offset, Some(i128::from(partner.start.0)), false));}}}}let late = plan.iter().map(|m| -m.2).max().unwrap_or(0).max(0);- let mut moves: Vec<(ClipId, TrackId, Tick)> = Vec::with_capacity(plan.len());- for (clip, track, start, was) in plan {+ let mut moves: Vec<(ClipId, TrackId, Tick, bool)> = Vec::with_capacity(plan.len());+ for (clip, track, start, was, new_track) in plan {// a partner that ends up where it is does not move (its listed clip only changed track):// re-placing it would drop the transitions at its edgesif was == Some(start + late) {continue;}let start = i64::try_from(start + late).ok().map(Tick).filter(|t| *t <= Tick::MAX).ok_or_else(|| bad(CMD, "`time` is out of range"))?;- moves.push((clip, track, start));+ moves.push((clip, track, start, new_track));}let ins = bool_p(p, "insert").unwrap_or(false);let copy = bool_p(p, "copy").unwrap_or(false);@@ -409,7 +408,7 @@ fn move_clips(s: &mut Session, p: &Value) -> Result<Value> {// Allocate destinations in the same transaction as the move: an invalid edit leaves// neither empty tracks nor history entries. Each source track keeps its clips together.let prepare = |q: &mut filmcraft_project::Sequence, ctx: &mut edit::EditCtx<'_>| -> Result<Vec<(ClipId, TrackId, Tick)>> {- let sources: Vec<_> = q.all_tracks().filter(|t| new_moves.iter().any(|m| m.1 == t.id)).map(|t| (t.id, t.kind, t.channels)).collect();+ let sources: Vec<_> = q.all_tracks().filter(|t| moves.iter().any(|m| m.3 && m.1 == t.id)).map(|t| (t.id, t.kind, t.channels)).collect();for kind in [TrackKind::Video, TrackKind::Audio] {let added = sources.iter().filter(|s| s.1 == kind).count();if added > 0 && q.tracks(kind).len().saturating_add(added) > crate::sequence_tools::MAX_TRACKS {@@ -428,8 +427,9 @@ fn move_clips(s: &mut Session, p: &Value) -> Result<Value> {}Ok(moves.iter()- .map(|&(clip, track, time)| {- let dest = new_moves.iter().find(|m| m.0 == clip).and_then(|m| destinations.iter().find(|d| d.0 == m.1)).map_or(track, |d| d.1);+ .map(|&(clip, track, time, new_track)| {+ // A copy can list the same source again with a different destination.+ let dest = destinations.iter().find(|d| new_track && d.0 == track).map_or(track, |d| d.1);(clip, dest, time)}).collect())@@ -575,12 +575,17 @@ pub fn linked_roll_pairs(seq: &filmcraft_project::Sequence, left: ClipId, right:pairs}-/// Expand a clip selection with linked partners (when linked selection is on).+/// Keep each selected identity once, then expand linked partners when linked selection is on.pub fn with_links(s: &Session, clips: &[ClipId]) -> Vec<ClipId> {- let Some(seq) = s.active_sequence() else { return clips.to_vec() };- let mut out = clips.to_vec();+ let mut out = Vec::new();+ for c in clips {+ if !out.contains(c) {+ out.push(*c);+ }+ }+ let Some(seq) = s.active_sequence() else { return out };if s.state.linked_selection {- let links: Vec<u64> = clips.iter().filter_map(|c| seq.find_item(*c).and_then(|(_, i)| i.link)).collect();+ let links: Vec<u64> = out.iter().filter_map(|c| seq.find_item(*c).and_then(|(_, i)| i.link)).collect();for t in seq.all_tracks() {for i in &t.items {if i.link.is_some_and(|l| links.contains(&l)) && !out.contains(&i.id) {diff --git a/crates/engine/src/keyboard.rs b/crates/engine/src/keyboard.rsindex 5d344943f..622bd5300 100644--- a/crates/engine/src/keyboard.rs+++ b/crates/engine/src/keyboard.rs@@ -226,7 +226,11 @@ fn nudge_track(s: &mut Session, up: bool) -> Result<Value> {let seq = s.active_sequence().ok_or(EngineError::NoSequence)?;let mut moves = Vec::new();let mut blocked = 0usize;+ let mut seen = std::collections::HashSet::new();for c in &s.state.selection {+ if !seen.insert(*c) {+ continue;+ }let Some((tid, it)) = seq.find_item(*c) else { continue };let Some(tr) = seq.track(tid) else { continue };let list = seq.tracks(tr.kind);diff --git a/crates/engine/src/timeline_move_tests.rs b/crates/engine/src/timeline_move_tests.rsindex f6aa640ff..3f4d32350 100644--- a/crates/engine/src/timeline_move_tests.rs+++ b/crates/engine/src/timeline_move_tests.rs@@ -36,6 +36,316 @@ fn pair_in_an_empty_sequence(s: &mut Session, seconds: f64) -> (TrackId, TrackIt(q.video_tracks[0].id, v, q.audio_tracks[0].id, a)}+fn assert_selection_edit_matches_control(s: &mut Session, selection: Vec<ClipId>, command: &str, params: serde_json::Value) {+ let before = s.project.clone();+ let undo = s.history.undo.len();+ let mut control = Session { project: s.project.clone(), state: s.state.clone(), history: s.history.clone(), media: s.media.clone(), ..Session::default() };+ control.state.selection = selection;+ let expected = control.execute(command, params.clone()).unwrap();+ let actual = s.execute(command, params).unwrap();+ assert_eq!(actual, expected, "{command} returns the unique-selection result");+ assert_eq!(s.project, control.project, "{command} produces the complete unique-selection project");+ assert_eq!(s.history.undo.len(), undo + 1, "the edit is one undo step");+ assert_eq!(s.history.undo, control.history.undo);+ assert_eq!(s.history.redo, control.history.redo);+ assert_eq!(s.history.merge_key, control.history.merge_key);+ let q = s.active_sequence().unwrap();+ let ids: Vec<ClipId> = q.all_tracks().flat_map(|t| t.items.iter().map(|i| i.id)).collect();+ assert_eq!(ids.iter().copied().collect::<std::collections::HashSet<_>>().len(), ids.len(), "no identity was duplicated");+ q.check().unwrap();+ let after = s.project.clone();+ s.execute("edit.undo", json!({})).unwrap();+ control.execute("edit.undo", json!({})).unwrap();+ assert_eq!(s.project, before, "undo restores the entire pre-edit project");+ assert_eq!(s.project, control.project);+ assert_eq!(s.history.undo, control.history.undo);+ assert_eq!(s.history.redo, control.history.redo);+ s.active_sequence().unwrap().check().unwrap();+ s.execute("edit.redo", json!({})).unwrap();+ control.execute("edit.redo", json!({})).unwrap();+ assert_eq!(s.project, after, "redo restores the entire edited project");+ assert_eq!(s.project, control.project);+ assert_eq!(s.history.undo, control.history.undo);+ assert_eq!(s.history.redo, control.history.redo);+ s.active_sequence().unwrap().check().unwrap();+}++#[test]+fn duplicate_selection_inputs_keep_first_occurrence_and_toggle_once() {+ for linked in [false, true] {+ let mut s = demo();+ let (_, v, _, a) = pair_in_an_empty_sequence(&mut s, 0.0);+ s.execute("sequence.linkedSelection", json!({"on": linked})).unwrap();+ let before = s.project.clone();+ let history = s.history.clone();+ let ids = json!([a.id.0, a.id.0, v.id.0, a.id.0, v.id.0]);+ let result = s.execute("timeline.select", json!({"clips": ids})).unwrap();+ assert_eq!(s.state.selection, vec![a.id, v.id], "explicit order precedes linked expansion");+ assert_eq!(result["selection"], json!([a.id.0, v.id.0]));+ s.execute("timeline.select", json!({"clips": [v.id.0, v.id.0], "add": true})).unwrap();+ assert_eq!(s.state.selection, vec![a.id, v.id], "adding an identity twice does not reorder the selection");+ s.execute("timeline.select", json!({"clips": ids, "toggle": true})).unwrap();+ assert!(s.state.selection.is_empty(), "each selected identity toggles off once");+ s.execute("timeline.select", json!({"clips": ids, "toggle": true})).unwrap();+ assert_eq!(s.state.selection, vec![a.id, v.id], "each unselected identity toggles on once");+ s.execute("timeline.select", json!({"clips": []})).unwrap();+ s.execute("timeline.select", json!({"clips": [v.id.0, v.id.0], "add": true})).unwrap();+ assert_eq!(s.state.selection, if linked { vec![v.id, a.id] } else { vec![v.id] });+ assert_eq!(s.project, before, "selection admission does not edit the project");+ assert_eq!(s.history.undo, history.undo);+ assert_eq!(s.history.redo, history.redo);+ s.active_sequence().unwrap().check().unwrap();+ }+}++#[test]+fn duplicate_selection_expansion_is_unique_without_an_active_sequence() {+ let clips = [ClipId(9), ClipId(3), ClipId(9), ClipId(3), ClipId(5)];+ for linked in [false, true] {+ let mut s = Session::default();+ s.state.linked_selection = linked;+ for active in [None, Some(filmcraft_project::ItemId(u64::MAX))] {+ s.state.active_sequence = active;+ let before = serde_json::to_value(&s.state).unwrap();+ assert_eq!(crate::commands::with_links(&s, &clips), vec![ClipId(9), ClipId(3), ClipId(5)]);+ assert_eq!(serde_json::to_value(&s.state).unwrap(), before);+ }+ }+}++#[test]+fn duplicate_selection_public_admission_keeps_nudges_equivalent_to_unique_selection() {+ for (command, linked) in [("timeline.nudgeRight", false), ("timeline.nudgeRight", true), ("timeline.nudgeUp", false)] {+ let mut s = demo();+ let (_, v, _, a) = pair_in_an_empty_sequence(&mut s, 60.0);+ s.execute("sequence.linkedSelection", json!({"on": linked})).unwrap();+ s.execute("timeline.select", json!({"clips": [v.id.0, v.id.0]})).unwrap();+ let selection = if linked { vec![v.id, a.id] } else { vec![v.id] };+ assert_eq!(s.state.selection, selection);+ assert_selection_edit_matches_control(&mut s, selection.clone(), command, json!({}));+ assert_eq!(s.state.selection, selection);+ }+}++#[test]+fn duplicate_selection_already_in_session_keeps_nudges_equivalent_to_unique_selection() {+ for linked in [false, true] {+ for command in ["timeline.nudgeRight", "timeline.nudgeUp"] {+ let mut s = demo();+ let (_, v, a_track, a) = pair_in_an_empty_sequence(&mut s, 60.0);+ s.execute("sequence.linkedSelection", json!({"on": linked})).unwrap();+ s.state.selection = vec![v.id, v.id, v.id];+ assert_selection_edit_matches_control(&mut s, vec![v.id], command, json!({}));+ let q = s.active_sequence().unwrap();+ if command == "timeline.nudgeUp" {+ assert_eq!(state(&s, v.id), (q.video_tracks[1].id, v.start));+ assert_eq!(state(&s, a.id), (a_track, a.start), "vertical nudges remain selected-only even with linked selection on");+ } else {+ assert_eq!(state(&s, v.id).1, v.start + s.sequence_rate().tick_of(1));+ assert_eq!(state(&s, a.id).1, a.start + if linked { s.sequence_rate().tick_of(1) } else { Tick::ZERO });+ }+ }+ }+}++#[test]+fn duplicate_selection_delete_matches_unique_selection_with_and_without_links() {+ for linked in [false, true] {+ for command in ["edit.clear", "edit.rippleDelete"] {+ let mut s = demo();+ let (_, v, a_track, a) = pair_in_an_empty_sequence(&mut s, 60.0);+ s.execute("sequence.linkedSelection", json!({"on": linked})).unwrap();+ if !linked {+ s.execute("timeline.setTrack", json!({"track": a_track.0, "syncLock": false})).unwrap();+ }+ s.state.selection = vec![v.id, v.id];+ assert_selection_edit_matches_control(&mut s, vec![v.id], command, json!({}));+ assert!(s.active_sequence().unwrap().find_item(v.id).is_none());+ assert_eq!(s.active_sequence().unwrap().find_item(a.id).is_none(), linked);+ assert!(s.state.selection.is_empty());+ }+ }+}++#[test]+fn duplicate_move_targets_are_rejected_and_retry_is_undoable() {+ for insert in [false, true] {+ let mut s = demo();+ let (_, v, _, _) = pair_in_an_empty_sequence(&mut s, 0.0);+ let before = s.project.clone();+ let undo = s.history.undo.len();+ let at = s.sequence_rate().tick_of(48).0;+ let result = s.execute(+ "timeline.move",+ json!({"moves": [{"clip": v.id.0, "track": "V1", "time": at}, {"clip": v.id.0, "track": "V2", "time": at}], "insert": insert, "linked": false}),+ );+ assert!(result.is_err(), "duplicate move entries were accepted: {result:?}");+ assert_eq!(s.project, before);+ assert_eq!(s.history.undo.len(), undo);+ s.execute("timeline.move", json!({"moves": [{"clip": v.id.0, "track": "V2", "time": at}], "insert": insert, "linked": false})).unwrap();+ let after = s.project.clone();+ assert_eq!(state(&s, v.id).1.0, at);+ s.execute("edit.undo", json!({})).unwrap();+ assert_eq!(s.project, before);+ s.execute("edit.redo", json!({})).unwrap();+ assert_eq!(s.project, after);+ }+}++fn reject_duplicate_new_track_move(s: &mut Session, clip: ClipId, insert: bool, linked: bool, new_first: bool) {+ s.state.selection = vec![clip];+ let before = s.project.clone();+ let selection = s.state.selection.clone();+ let editor_state = serde_json::to_value(&s.state).unwrap();+ let history = s.history.clone();+ let journal = s.journal.clone();+ let at = s.sequence_rate().tick_of(48).0;+ let tracks = if new_first { ["new", "V2"] } else { ["V2", "new"] };+ let result = s.execute(+ "timeline.move",+ json!({"moves": [{"clip": clip.0, "track": tracks[0], "time": at}, {"clip": clip.0, "track": tracks[1], "time": at}], "insert": insert, "linked": linked}),+ );+ assert!(matches!(result, Err(EngineError::Edit(filmcraft_edit::EditError::Other(_)))), "duplicate move entries must be rejected: {result:?}");+ assert_eq!(s.project, before, "the project and its id allocator stay unchanged");+ assert_eq!(s.state.selection, selection);+ assert_eq!(serde_json::to_value(&s.state).unwrap(), editor_state);+ assert_eq!(s.history.undo.len(), history.undo.len(), "no oldest undo entry is evicted");+ assert_eq!(s.history.redo.len(), history.redo.len(), "no existing redo entry is lost");+ assert_eq!(s.history.undo, history.undo);+ assert_eq!(s.history.redo, history.redo);+ assert_eq!(s.history.merge_key, history.merge_key);+ assert_eq!(s.history.limit, history.limit);+ assert_eq!(s.journal, journal, "the failed command is not journaled");+}++#[test]+fn duplicate_new_track_move_preserves_redo_and_retry_is_undoable() {+ for insert in [false, true] {+ for linked in [false, true] {+ for new_first in [false, true] {+ let mut s = demo();+ let (_, v, _, _) = pair_in_an_empty_sequence(&mut s, 0.0);+ s.execute("timeline.setTrack", json!({"track": "V2", "locked": true})).unwrap();+ let redo_project = s.project.clone();+ s.execute("edit.undo", json!({})).unwrap();+ assert!(!s.history.redo.is_empty());+ reject_duplicate_new_track_move(&mut s, v.id, insert, linked, new_first);+ let before = s.project.clone();+ s.execute("edit.redo", json!({})).unwrap();+ assert_eq!(s.project, redo_project, "the previously available redo still works");+ s.execute("edit.undo", json!({})).unwrap();+ assert_eq!(s.project, before);+ let at = s.sequence_rate().tick_of(48).0;+ s.execute("timeline.move", json!({"moves": [{"clip": v.id.0, "track": "new", "time": at}], "insert": insert, "linked": linked})).unwrap();+ let after = s.project.clone();+ assert_eq!(state(&s, v.id).1.0, at);+ assert_eq!(s.active_sequence().unwrap().video_tracks.len(), 3);+ s.active_sequence().unwrap().check().unwrap();+ s.execute("edit.undo", json!({})).unwrap();+ assert_eq!(s.project, before, "one undo removes the new track and restores the move");+ s.execute("edit.redo", json!({})).unwrap();+ assert_eq!(s.project, after);+ }+ }+ }+}++#[test]+fn duplicate_new_track_move_preserves_full_undo_history() {+ for insert in [false, true] {+ for linked in [false, true] {+ for new_first in [false, true] {+ let mut s = demo();+ let (_, v, _, _) = pair_in_an_empty_sequence(&mut s, 0.0);+ assert_eq!(s.history.limit, 200);+ while s.history.undo.len() < s.history.limit {+ let step = s.history.undo.len();+ s.edit_merged("History step", &format!("history-{step}"), |project, _| {+ project.root.name = format!("History {step}");+ Ok(())+ })+ .unwrap();+ }+ assert_eq!(s.history.undo.len(), s.history.limit);+ assert!(s.history.merge_key.is_some());+ reject_duplicate_new_track_move(&mut s, v.id, insert, linked, new_first);+ let oldest = s.history.undo.first().unwrap().1.clone();+ for _ in 0..s.history.limit {+ s.execute("edit.undo", json!({})).unwrap();+ }+ assert_eq!(s.project, oldest, "every retained undo step remains usable");+ }+ }+ }+}++#[test]+fn unique_new_track_moves_keep_linked_partner_behavior() {+ for insert in [false, true] {+ for linked in [false, true] {+ let mut s = demo();+ let (_, v, a_track, a) = pair_in_an_empty_sequence(&mut s, 0.0);+ let before = s.project.clone();+ let undo = s.history.undo.len();+ let to = s.sequence_rate().tick_of(48);+ let result =+ s.execute("timeline.move", json!({"moves": [{"clip": v.id.0, "track": "new", "time": to.0}], "insert": insert, "linked": linked})).unwrap();+ let sequence = s.active_sequence().unwrap();+ assert_eq!(sequence.video_tracks.len(), 3);+ assert_eq!(state(&s, v.id), (sequence.video_tracks[2].id, to));+ assert_eq!(state(&s, a.id), (a_track, if linked { to } else { a.start }));+ assert_eq!(result["moved"], if linked { json!([v.id.0, a.id.0]) } else { json!([v.id.0]) });+ assert_eq!(s.history.undo.len(), undo + 1);+ sequence.check().unwrap();+ let after = s.project.clone();+ s.execute("edit.undo", json!({})).unwrap();+ assert_eq!(s.project, before);+ s.execute("edit.redo", json!({})).unwrap();+ assert_eq!(s.project, after);+ }+ }+}++#[test]+fn repeated_new_track_copy_destinations_get_distinct_ids() {+ for insert in [false, true] {+ for linked in [false, true] {+ for new_first in [false, true] {+ let mut s = demo();+ let (v_track, v, a_track, a) = pair_in_an_empty_sequence(&mut s, 0.0);+ let before = s.project.clone();+ let undo = s.history.undo.len();+ let to = s.active_sequence().unwrap().duration() + s.sequence_rate().tick_of(48);+ let tracks = if new_first { ["new", "V2"] } else { ["V2", "new"] };+ let result = s+ .execute(+ "timeline.move",+ json!({"moves": [{"clip": v.id.0, "track": tracks[0], "time": to.0}, {"clip": v.id.0, "track": tracks[1], "time": to.0}], "insert": insert, "linked": linked, "copy": true}),+ )+ .unwrap();+ let copies: Vec<ClipId> = result["copied"].as_array().unwrap().iter().map(|c| ClipId(c.as_u64().unwrap())).collect();+ assert_eq!(copies.len(), if linked { 3 } else { 2 });+ assert_eq!(copies.iter().copied().collect::<std::collections::HashSet<_>>().len(), copies.len());+ assert!(!copies.contains(&v.id) && !copies.contains(&a.id));+ assert_eq!((state(&s, v.id), state(&s, a.id)), ((v_track, v.start), (a_track, a.start)));+ assert_eq!(s.state.selection, copies);+ let sequence = s.active_sequence().unwrap();+ assert_eq!(sequence.video_tracks.len(), 3);+ assert!(copies.iter().all(|c| sequence.find_item(*c).is_some()), "every reported copy exists");+ assert!(copies.iter().any(|c| state(&s, *c) == (sequence.video_tracks[2].id, to)));+ assert!(copies.iter().any(|c| state(&s, *c) == (sequence.video_tracks[1].id, to)));+ assert_eq!(s.history.undo.len(), undo + 1);+ sequence.check().unwrap();+ let after = s.project.clone();+ s.execute("edit.undo", json!({})).unwrap();+ assert_eq!(s.project, before);+ s.execute("edit.redo", json!({})).unwrap();+ assert_eq!(s.project, after);+ }+ }+ }+}+/// `timeline.move` of one clip left its linked sound behind although Linked Selection was on.#[test]fn move_takes_linked_partners_along() {diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex edb5646e4..98a72b4da 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -2688,8 +2688,10 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &Drag::Move { clips, offset, track_delta, new_track, copy, .. } if offset != Tick::ZERO || track_delta != 0 || new_track.is_some() => {// #1104: dropped past the last track, the clips go onto a new onelet to = |tid| new_track.map_or_else(|| json!(shift_track(seq, tid, track_delta).unwrap_or(tid).0), |_| json!("new"));+ let mut seen = std::collections::HashSet::new();let moves: Vec<Value> = clips.iter()+ .filter(|c| seen.insert(**c)).filter_map(|c| seq.find_item(*c).map(|(tid, it)| json!({"clip": c.0, "track": to(tid), "time": (it.start + offset).max(Tick::ZERO).0}))).collect();// Option held while dropping copies (Premiere: Option-drag duplicates)diff --git a/crates/ui-egui/tests/timeline_option_drag_ui.rs b/crates/ui-egui/tests/timeline_option_drag_ui.rsindex 01840f43d..0593d8296 100644--- a/crates/ui-egui/tests/timeline_option_drag_ui.rs+++ b/crates/ui-egui/tests/timeline_option_drag_ui.rs@@ -90,3 +90,40 @@ fn option_drag_copies_a_clip_and_a_plain_drag_moves_it() {assert_eq!(clip_count(&mut d), n);assert!(d.harness.state().session.active_sequence().unwrap().find_item(v2.id).unwrap().1.start > v2.start, "moved");}++#[test]+fn dragging_after_frame_hold_with_repeated_clip_arguments_edits_once() {+ for copy in [false, true] {+ let mut d = Driver::demo();+ let original = d.harness.state().session.active_sequence().unwrap().video_tracks[1].items[0].clone();+ d.exec("clip.frameHold", json!({"clips": [original.id.0, original.id.0], "time": original.start.0}));+ let before = d.harness.state().session.project.clone();+ let undo = d.harness.state().session.history.undo.len();+ let n = clip_count(&mut d);+ let r = d.rect(&format!("timeline.clip.{}", original.id.0));+ let (x, y) = (r[0] + 10.0, r[1] + r[3] / 2.0);+ d.ok("ui.drag", json!({"from": {"x": x, "y": y}, "to": {"x": x + 240.0, "y": y}, "steps": 12, "modifiers": {"alt": copy}}));+ d.frames(3);+ let s = &d.harness.state().session;+ let q = s.active_sequence().unwrap();+ if copy {+ assert_eq!(s.state.selection.len(), 1, "one selected clip produces one copy");+ let copied = s.state.selection[0];+ assert_ne!(copied, original.id);+ assert!(q.find_item(copied).unwrap().1.start > original.start);+ assert_eq!(q.find_item(original.id).unwrap().1.start, original.start);+ } else {+ assert!(q.find_item(original.id).unwrap().1.start > original.start, "a repeated selection must still drag");+ }+ let ids: Vec<_> = q.all_tracks().flat_map(|t| t.items.iter().map(|i| i.id)).collect();+ assert_eq!(ids.len(), n + usize::from(copy));+ assert_eq!(ids.iter().copied().collect::<std::collections::HashSet<_>>().len(), ids.len());+ q.check().unwrap();+ assert_eq!(s.history.undo.len(), undo + 1);+ let after = s.project.clone();+ d.exec("edit.undo", json!({}));+ assert_eq!(d.harness.state().session.project, before);+ d.exec("edit.redo", json!({}));+ assert_eq!(d.harness.state().session.project, after);+ }+}