FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
sequence.addEdit: selected clips under the playhead are cut, and only they (#164)
carlitosteso3d47e794437c8
diff --git a/crates/engine/src/clip_ops_tests.rs b/crates/engine/src/clip_ops_tests.rsindex 4a5031772..fb4572232 100644--- a/crates/engine/src/clip_ops_tests.rs+++ b/crates/engine/src/clip_ops_tests.rs@@ -851,3 +851,27 @@ fn a_cyclic_subclip_chain_has_no_media_duration() {*parent = sub;assert_eq!(crate::media_duration(&s.project, &s.media, sub), None);}++/// #164: Add Edit with a clip selected cut every targeted track. Like Premiere it now cuts only+/// the selected clips under the playhead; with nothing selected there, the targeted tracks.+#[test]+fn add_edit_cuts_only_the_selected_clips() {+ let mut s = demo();+ let count = |s: &Session| {+ let q = s.active_sequence().unwrap();+ (q.video_tracks.iter().map(|t| t.items.len()).sum::<usize>(), q.audio_tracks.iter().map(|t| t.items.len()).sum::<usize>())+ };+ // a V1 clip and a time inside it+ let first = v1(&s)[1].clone();+ let t = first.start + filmcraft_time::Tick(first.duration.0 / 2);+ let (v0, a0) = count(&s);+ s.state.selection = vec![first.id];+ s.execute("sequence.addEdit", json!({"time": t.0})).unwrap();+ let (v1n, a1n) = count(&s);+ assert_eq!((v1n, a1n), (v0 + 1, a0), "only the selected V1 clip is cut");+ // nothing selected under the playhead: every targeted track is cut+ s.execute("edit.undo", json!({})).unwrap();+ s.state.selection.clear();+ let r = s.execute("sequence.addEdit", json!({"time": t.0})).unwrap();+ assert!(r["cuts"].as_u64().unwrap() > 1, "{r}");+}diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rsindex 23f2dccd9..cf7b86697 100644--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@ -1333,8 +1333,17 @@ fn build() -> Vec<CommandSpec> {}),cmd!("sequence.addEdit", "Add Edit", ["Sequence"], Some("Cmd+K"), r#"{"time":ticks?}"#, has_seq, |s, p| {let t = time_p(s, p, "").unwrap_or(s.playhead());- let tg = s.targeting().targeted;- let n = s.edit_sequence("Add Edit", |q, ctx, _| Ok(edit::razor(q, &tg, t, ctx)))?;+ // Like Premiere: selected clips under the playhead are cut, and only they (#164);+ // with none, the targeted tracks are.+ let sel = s.state.selection.clone();+ let selected_here =+ s.active_sequence().is_some_and(|q| sel.iter().any(|c| q.find_item(*c).is_some_and(|(_, it)| it.start < t && t < it.start + it.duration)));+ let n = if selected_here {+ s.edit_sequence("Add Edit", |q, ctx, _| Ok(edit::razor_items(q, &sel, t, ctx)))?+ } else {+ let tg = s.targeting().targeted;+ s.edit_sequence("Add Edit", |q, ctx, _| Ok(edit::razor(q, &tg, t, ctx)))?+ };Ok(json!({"cuts": n.len()}))}),cmd!("sequence.addEditAllTracks", "Add Edit to All Tracks", ["Sequence"], Some("Cmd+Shift+K"), r#"{"time":ticks?}"#, has_seq, |s, p| {