Skip to content

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

shortcuts: Delete clears the selected timeline clips (#243)

wstock06abca1bb9f8
diff --git a/crates/engine/src/shortcut_presets.rs b/crates/engine/src/shortcut_presets.rs
index 118f2991e..7e105e509 100644
--- a/crates/engine/src/shortcut_presets.rs
+++ b/crates/engine/src/shortcut_presets.rs
@@ -11,6 +11,9 @@ pub type Entry = (&'static str, &'static str, &'static str);
/// FilmCraft additions to the per-command defaults: panel-specific shortcuts.
pub const FILMCRAFT_PANEL: &[Entry] = &[
("project.delete", "Backspace", "Project"),
+ // the forward-delete key (Delete on Windows and Linux keyboards) clears timeline clips too;
+ // application-wide it is Project ▸ Clear (#243)
+ ("edit.clear", "Delete", "Timeline"),
("file.newBin", "Cmd+B", "Project"),
("edit.undo", "Left", "History"),
("edit.redo", "Right", "History"),
diff --git a/crates/engine/src/shortcuts_tests.rs b/crates/engine/src/shortcuts_tests.rs
index 0bf0b63b9..d12242333 100644
--- a/crates/engine/src/shortcuts_tests.rs
+++ b/crates/engine/src/shortcuts_tests.rs
@@ -132,6 +132,19 @@ fn panel_shortcuts_override_application_ones_with_focus() {
assert!(k.as_array().unwrap().iter().any(|b| b["command"] == "edit.copy" && b["keys"] == "Ctrl+C"), "{k}");
}
+#[test]
+fn delete_clears_timeline_clips_and_project_items() {
+ // #243: with the Timeline focused, Delete (the forward-delete key, labelled Delete on Windows
+ // and Linux keyboards) resolved to Project ▸ Clear and left the selected clips in place.
+ let s = Session::default();
+ let del = Chord::parse("Delete").unwrap();
+ for p in [Platform::Mac, Platform::Windows] {
+ assert_eq!(s.shortcuts.resolve(&del, Some("Timeline"), p).unwrap().command, "edit.clear", "{p:?}");
+ assert_eq!(s.shortcuts.resolve(&del, Some("Project"), p).unwrap().command, "project.delete", "{p:?}");
+ assert_eq!(s.shortcuts.resolve(&del, None, p).unwrap().command, "project.delete", "{p:?}");
+ }
+}
+
#[test]
fn compat_presets_map_other_editors() {
let mut s = Session::default();
diff --git a/crates/ui-egui/tests/keyboard_ui.rs b/crates/ui-egui/tests/keyboard_ui.rs
index 67020b7fb..2fe5dac50 100644
--- a/crates/ui-egui/tests/keyboard_ui.rs
+++ b/crates/ui-egui/tests/keyboard_ui.rs
@@ -179,3 +179,21 @@ fn new_keys_work_in_the_app() {
d.key("Cmd+Shift+0");
assert_eq!(d.app().ui.program.zoom, None);
}
+
+#[test]
+fn delete_key_clears_the_selected_timeline_clip() {
+ // #243: on Windows and Linux keyboards Delete is the forward-delete key; with the Timeline
+ // focused it ran Project ▸ Clear (nothing selected there), so the clip stayed.
+ let mut d = Driver::new();
+ let items = |d: &mut Driver| d.exec("sequence.inspect", json!({}))["video"][0]["items"].as_array().unwrap().clone();
+ let second = items(&mut d)[1].clone();
+ let (clip, start) = (second["clip"].as_u64().unwrap(), second["start"].as_i64().unwrap());
+ d.exec("playhead.set", json!({"time": start + 1_000_000_000}));
+ d.focus("Timeline");
+ d.key("D");
+ assert!(d.app().session.state.selection.iter().any(|c| c.0 == clip), "D selects the clip under the playhead");
+ d.key("Delete");
+ assert!(!items(&mut d).iter().any(|i| i["clip"].as_u64() == Some(clip)), "Delete removed the selected clip");
+ d.key("Cmd+Z");
+ assert!(items(&mut d).iter().any(|i| i["clip"].as_u64() == Some(clip)), "and undo brings it back");
+}