Skip to content

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

#680: Shift+Delete ripple deletes with the Timeline focused

vangel7686856f18b9d2
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 857f42a56..86fcb8eb0 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1285,7 +1285,10 @@ impl FilmcraftApp {
if self.session.trim_play.dynamic.is_some() && ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
let _ = self.session.execute("trim.cancelDynamic", json!({}));
}
- // Panel shortcuts of the focused panel first: they override application shortcuts.
+ // Panel shortcuts of the focused panel override application shortcuts on the same chord.
+ // egui ignores extra Shift and Alt when matching, so the most specific chords go first
+ // across both scopes (the sort is stable, so the panel still wins a tie): otherwise the
+ // Timeline's `Delete` (Clear) swallows the app-wide `Shift+Delete` (Ripple Delete) (#680).
let focused = self.ui.focused.title();
let mut fire = Vec::new();
ctx.input_mut(|i| {
@@ -1293,7 +1296,9 @@ impl FilmcraftApp {
clipboard_events_as_keys(&mut i.events, modifiers);
let panel = self.bindings.iter().filter(|b| b.3.as_deref() == Some(focused));
let app_wide = self.bindings.iter().filter(|b| b.3.is_none());
- for (m, k, id, _) in panel.chain(app_wide) {
+ let mut candidates: Vec<&menus::KeyBinding> = panel.chain(app_wide).collect();
+ candidates.sort_by_key(|b| std::cmp::Reverse(menus::specificity(b.0)));
+ for (m, k, id, _) in candidates {
if i.consume_key(*m, *k) {
fire.push(id.clone());
}
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 9dff12d38..d47a525ec 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -683,10 +683,16 @@ pub fn bindings(app: &FilmcraftApp) -> Vec<KeyBinding> {
let shifted: Vec<KeyBinding> =
v.iter().filter(|b| b.0.shift).filter_map(|(m, k, id, p)| shifted_key(*k).map(|k2| (*m, k2, id.clone(), p.clone()))).collect();
v.extend(shifted);
- v.sort_by_key(|(m, ..)| std::cmp::Reverse(m.command as u8 + m.shift as u8 + m.alt as u8 + m.ctrl as u8));
+ v.sort_by_key(|(m, ..)| std::cmp::Reverse(specificity(*m)));
v
}
+/// How many modifiers a chord names: chords naming more are matched first, because egui ignores
+/// extra Shift and Alt when matching a key press.
+pub fn specificity(m: egui::Modifiers) -> u8 {
+ m.command as u8 + m.shift as u8 + m.alt as u8 + m.ctrl as u8
+}
+
/// The key a US layout reports for `k` with Shift held, when it differs.
fn shifted_key(k: egui::Key) -> Option<egui::Key> {
use egui::Key;
diff --git a/crates/ui-egui/tests/keyboard_ui.rs b/crates/ui-egui/tests/keyboard_ui.rs
index 036606320..52ece3995 100644
--- a/crates/ui-egui/tests/keyboard_ui.rs
+++ b/crates/ui-egui/tests/keyboard_ui.rs
@@ -238,3 +238,27 @@ fn delete_key_clears_the_selected_timeline_clip() {
d.key("Cmd+Z");
assert!(items(&mut d).iter().any(|i| i["clip"].as_u64() == Some(clip)), "and undo brings it back");
}
+
+#[test]
+fn shift_delete_ripple_deletes_with_the_timeline_focused() {
+ // #680: the Timeline's own `Delete` (Clear) was tried before the app-wide `Shift+Delete`
+ // (Ripple Delete), and egui ignores the extra Shift, so Shift+Delete left a gap.
+ let mut d = Driver::new();
+ // the demo's other tracks have clips in the way of a sync-locked ripple
+ for t in ["V2", "V3", "A2", "A3"] {
+ d.exec("timeline.setTrack", json!({"track": t, "syncLock": false}));
+ }
+ let items = |d: &mut Driver| d.exec("sequence.inspect", json!({}))["video"][0]["items"].as_array().unwrap().clone();
+ let v1 = items(&mut d);
+ let (clip, start) = (v1[1]["clip"].as_u64().unwrap(), v1[1]["start"].as_i64().unwrap());
+ let next = v1[2]["clip"].as_u64().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("Shift+Delete");
+ let after = items(&mut d);
+ assert!(!after.iter().any(|i| i["clip"].as_u64() == Some(clip)), "Shift+Delete removed the selected clip");
+ let moved = after.iter().find(|i| i["clip"].as_u64() == Some(next)).map(|i| i["start"].as_i64().unwrap());
+ assert_eq!(moved, Some(start), "and closed the gap");
+}