Skip to content

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

project: Clear counts each item and bin once

punkhop64d41b266a74
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index 055539934..06101fef0 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -2094,7 +2094,7 @@ fn build() -> Vec<CommandSpec> {
p.get("items").and_then(Value::as_array).map(|a| a.iter().filter_map(|v| v.as_u64().map(ItemId)).collect()).unwrap_or_default();
Ok(Value::Null)
}),
- cmd!("project.delete", "Clear", [], Some("Delete"), r#"{"items":[id|binId]?}"#, has_project_selection, |s, p| {
+ cmd!("project.delete", "Clear", [], Some("Delete"), r#"{"items":[id]?}"#, has_project_selection, |s, p| {
let asked: Vec<ItemId> = p
.get("items")
.and_then(Value::as_array)
@@ -2102,14 +2102,22 @@ fn build() -> Vec<CommandSpec> {
.unwrap_or_else(|| s.state.project_selection.clone());
// A bin named here goes with everything in it, as in the Project panel of any editor.
let root = s.project.root.id;
- let bins: Vec<filmcraft_project::BinId> =
+ let named: Vec<filmcraft_project::BinId> =
asked.iter().map(|i| filmcraft_project::BinId(i.0)).filter(|b| *b != root && s.project.root.find_bin(*b).is_some()).collect();
- let mut items: Vec<ItemId> = asked.iter().copied().filter(|i| !bins.contains(&filmcraft_project::BinId(i.0))).collect();
+ // a bin inside another named bin goes with that one
+ let bins: Vec<filmcraft_project::BinId> = named
+ .iter()
+ .copied()
+ .filter(|b| !named.iter().any(|o| o != b && s.project.root.find_bin(*o).is_some_and(|o| o.find_bin(*b).is_some())))
+ .collect();
+ let mut items: Vec<ItemId> = asked.iter().copied().filter(|i| !named.contains(&filmcraft_project::BinId(i.0))).collect();
for b in &bins {
if let Some(bin) = s.project.root.find_bin(*b) {
bin.all_items(&mut items);
}
}
+ items.sort_by_key(|i| i.0);
+ items.dedup();
s.edit("Clear", |pr, st| {
for b in &bins {
pr.root.remove_bin(*b);
diff --git a/crates/engine/src/project_tools_tests.rs b/crates/engine/src/project_tools_tests.rs
index 1bbfb4294..11b7bd497 100644
--- a/crates/engine/src/project_tools_tests.rs
+++ b/crates/engine/src/project_tools_tests.rs
@@ -431,6 +431,12 @@ fn clear_deletes_a_bin_with_everything_in_it() {
s.execute("edit.undo", json!({})).unwrap();
assert!(s.project.root.find_bin(filmcraft_project::BinId(inner)).is_some());
assert_eq!(s.project.root.parent_of(ocean), Some(filmcraft_project::BinId(inner)));
+ // the clip, its bin and the bin around it all named: each counted once
+ select(&mut s);
+ let r = s.execute("project.delete", json!({"items": [ocean.0, inner, outer]})).unwrap();
+ assert_eq!(r, json!({"items": 1, "bins": 1}));
+ assert_eq!(s.project.items.len(), before - 1);
+ s.execute("edit.undo", json!({})).unwrap();
// the project's own top bin is never cleared
let root = s.project.root.id.0;
select(&mut s);