FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Clear leftover Project item selection when making a new bin.
Vikram Bhaskarand4ec47a4a3e6
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 38ee823ca..5f8981665 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1411,6 +1411,7 @@ impl FilmcraftApp {}// Clear in the Project panel removes the selected bin when no item is selected (#587).let clear = if self.ui.focused == PanelKind::Project && id == "project.delete" {+ self.ui.project_panel.rename = None;crate::panels::project_views::clear_params(&self.session.state.project_selection, self.ui.project_panel.selected_bin)} else {Nonediff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rsindex 9aef769ed..95932cb16 100644--- a/crates/ui-egui/src/panels/project.rs+++ b/crates/ui-egui/src/panels/project.rs@@ -625,7 +625,10 @@ fn footer(app: &mut FilmcraftApp, ui: &mut egui::Ui, bar: Rect, v: &View, actionactions.push(("file.newBin".into(), json!({"parent": parent, "panel": pre})));}"project.delete" => match crate::panels::project_views::clear_params(&app.session.state.project_selection, app.ui.project_panel.selected_bin) {- Some(p) => actions.push((id.into(), p)),+ Some(p) => {+ app.ui.project_panel.rename = None;+ actions.push((id.into(), p));+ }None => app.ui.status = tl!("Select items to clear").into(),},_ => actions.push((id.into(), json!({}))),@@ -732,6 +735,7 @@ pub fn panel_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui) -> bool {actions.push(("projectPanel.rename".into(), json!({})));}if item(ui, "delete", tl!("Delete"), clear.is_some(), Some("Backspace")) {+ app.ui.project_panel.rename = None;actions.push(("project.delete".into(), clear.unwrap_or_default()));}ui.separator();@@ -979,6 +983,9 @@ pub fn new_bin(app: &mut FilmcraftApp, params: &Value) -> Result<Value, String>app.ui.expanded_bins.push(p);}let panel = params.get("panel").and_then(Value::as_str).map_or(shown.prefix, str::to_string);+ // Clicking a bin already clears the item selection so Clear targets the bin (#587). New Bin+ // must do the same: leftover clips would otherwise steal the trash button and Delete.+ let _ = app.session.execute("project.select", json!({"items": []}));app.ui.project_panel.selected_bin = Some(bin);app.ui.project_panel.rename = Some(Rename { item: None, bin: Some(bin), text, panel });Ok(r)diff --git a/crates/ui-egui/tests/project_panel_ui.rs b/crates/ui-egui/tests/project_panel_ui.rsindex d4ee713e6..25b9e294e 100644--- a/crates/ui-egui/tests/project_panel_ui.rs+++ b/crates/ui-egui/tests/project_panel_ui.rs@@ -570,6 +570,29 @@ fn new_bin_asks_for_its_name() {assert!(d.app().ui.project_panel.rename.is_none());}+#[test]+fn new_bin_then_clear_removes_the_bin() {+ // leftover Project item selection must not keep Clear from removing the new bin+ let mut d = project_driver();+ d.exec("project.view.set", json!({"view": "list"}));+ d.click("project.button.new-item");+ d.wait_for("project.newItem.file.newColorMatte");+ d.click("project.newItem.file.newColorMatte");+ d.click("colorMatte.ok");+ let items0 = d.app().session.project.items.len();+ let bins0 = d.app().session.project.root.children.len();+ assert!(!d.app().session.state.project_selection.is_empty());+ d.click("project.button.file.newBin");+ d.frames(2);+ let bin = d.app().ui.project_panel.selected_bin.expect("the new bin is selected");+ assert!(d.app().session.state.project_selection.is_empty(), "New Bin clears leftover item selection");+ d.click("project.button.project.delete");+ d.frames(2);+ assert!(d.app().session.project.root.find_bin(filmcraft_project::BinId(bin)).is_none(), "Clear removes the new bin");+ assert_eq!(d.app().session.project.root.children.len(), bins0);+ assert_eq!(d.app().session.project.items.len(), items0, "clips already in the project stay");+}+// ------------------------------------------------------------------------------------ Media Browserfn media_dir(tag: &str) -> std::path::PathBuf {