Skip to content

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

Fix Clear on Close Sequence also dropping File Close (Cmd+W).

Vikram Bhaskarand3444534a66f
diff --git a/crates/engine/src/shortcuts.rs b/crates/engine/src/shortcuts.rs
index 0c9e47718..b24362989 100644
--- a/crates/engine/src/shortcuts.rs
+++ b/crates/engine/src/shortcuts.rs
@@ -737,7 +737,7 @@ impl Shortcuts {
let nb = Binding { command: command.into(), keys: chord.canonical(), panel: panel.map(str::to_string) };
let before = self.snapshot();
if !add {
- self.bindings.retain(|b| !(b.command == command && b.context() == nb.context()));
+ self.bindings.retain(|b| !(same_shortcut_command(&b.command, command) && b.context() == nb.context()));
}
let mut reassigned = Vec::new();
if !keep_conflicts {
@@ -768,9 +768,19 @@ impl Shortcuts {
};
let before = self.snapshot();
let n0 = self.bindings.len();
+ let twins = shortcut_twins(command);
self.bindings.retain(|b| {
- let hit = b.command == command && chord.as_ref().is_none_or(|c| b.chord().as_ref() == Some(c)) && panel.as_ref().is_none_or(|p| &b.panel == p);
- !hit
+ let cmd = same_shortcut_command(&b.command, command);
+ let key_ok = chord.as_ref().is_none_or(|c| b.chord().as_ref() == Some(c));
+ // File ▸ Close and Close Sequence share Cmd+W (app + Timeline). The editor's Clear
+ // always sends panel Application; treating that as every context for this pair is
+ // what actually frees the chord (#773).
+ let panel_ok = match &panel {
+ None => true,
+ Some(p) if p.is_none() && twins => true,
+ Some(p) => &b.panel == p,
+ };
+ !(cmd && key_ok && panel_ok)
});
let n = n0 - self.bindings.len();
if n > 0 {
@@ -909,12 +919,12 @@ impl Shortcuts {
// ---------------------------------------------------------------- queries
pub fn for_command(&self, id: &str) -> Vec<&Binding> {
- self.bindings.iter().filter(|b| b.command == id).collect()
+ self.bindings.iter().filter(|b| same_shortcut_command(&b.command, id)).collect()
}
/// The shortcut menus show: the first application-wide one.
pub fn primary(&self, id: &str) -> Option<String> {
- self.bindings.iter().find(|b| b.command == id && b.panel.is_none()).map(|b| b.keys.clone())
+ self.bindings.iter().find(|b| same_shortcut_command(&b.command, id) && b.panel.is_none()).map(|b| b.keys.clone())
}
/// The command a chord runs with `panel` focused (panel shortcuts first).
@@ -998,6 +1008,15 @@ fn panel_opt(p: &str) -> Option<&str> {
if p.is_empty() { None } else { Some(p) }
}
+/// `file.close` is File ▸ Close: the same action as `sequence.close` (Close Sequence).
+fn shortcut_twins(id: &str) -> bool {
+ id == "file.close" || id == "sequence.close"
+}
+
+fn same_shortcut_command(bound: &str, target: &str) -> bool {
+ bound == target || (shortcut_twins(bound) && shortcut_twins(target))
+}
+
fn check_panel(panel: Option<&str>) -> std::result::Result<Option<&'static str>, String> {
match panel {
None => Ok(None),
diff --git a/crates/engine/src/shortcuts_tests.rs b/crates/engine/src/shortcuts_tests.rs
index 9ffd35f4d..c589086d8 100644
--- a/crates/engine/src/shortcuts_tests.rs
+++ b/crates/engine/src/shortcuts_tests.rs
@@ -113,6 +113,26 @@ fn assign_reassigns_conflicts_and_undoes() {
assert!(s.shortcuts.for_command("edit.undo").is_empty());
}
+#[test]
+fn clear_close_sequence_also_clears_file_close() {
+ // #773: File ▸ Close (`file.close`, Cmd+W) aliases Close Sequence (`sequence.close`).
+ // The editor's Clear sends panel Application against `sequence.close`, which had only a
+ // Timeline binding — Cmd+W stayed on `file.close`.
+ let mut s = Session::default();
+ assert_eq!(s.shortcuts.primary("file.close").as_deref(), Some("Cmd+W"));
+ assert_eq!(s.shortcuts.primary("sequence.close").as_deref(), Some("Cmd+W"));
+ assert!(s.shortcuts.for_command("sequence.close").iter().any(|b| b.keys == "Cmd+W"));
+ let r = s.execute("shortcuts.clear", json!({"command": "sequence.close", "panel": "Application"})).unwrap();
+ assert!(r["removed"].as_u64().unwrap() >= 1, "{r}");
+ assert!(s.shortcuts.for_command("sequence.close").is_empty(), "{:?}", s.shortcuts.for_command("sequence.close"));
+ assert!(s.shortcuts.primary("file.close").is_none());
+ let w = Chord::parse("Cmd+W").unwrap();
+ assert!(s.shortcuts.resolve(&w, None, Platform::current()).is_none());
+ assert!(s.shortcuts.resolve(&w, Some("Timeline"), Platform::current()).is_none());
+ s.execute("shortcuts.set", json!({"command": "sequence.addEdit", "keys": "Cmd+W", "add": true})).unwrap();
+ assert_eq!(s.shortcuts.resolve(&w, None, Platform::current()).unwrap().command, "sequence.addEdit");
+}
+
#[test]
fn panel_shortcuts_override_application_ones_with_focus() {
let s = Session::default();