GitCorner

Code

ossartcraftfilmcraft🌐
f67d38b35cc5
use super::{Dialog, FilmcraftApp, PanelKind, dock, dock_ui, json, menus, panels};

impl FilmcraftApp {
    /// Per-pass shortcut handling: reset the pasted image, rebuild bindings only when the shortcut revision or workspace set changes, and leave unmodified keys
    /// to a focused text field except dock dividers.
    pub(super) fn handle_shortcuts(&mut self, ctx: &egui::Context) {
        // A paste image payload belongs to the paste event in this pass only.
        self.pasted_image = None;
        let workspaces = (dock::names(&self.workspaces), self.ui.workspace.clone());
        if self.bindings_rev != self.session.shortcuts.revision || workspaces != self.menu_workspaces {
            self.menu_workspaces = workspaces;
            self.bindings = menus::bindings(self);
            self.bindings_rev = self.session.shortcuts.revision;
        }
        // Esc exits cinema mode unconditionally, even when a dialog or text field has focus.
        if self.ui.fullscreen_program && ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
            self.ui.fullscreen_program = false;
            let restore = self.ui.cinema_was_fullscreen;
            if let Some(prev) = self.ui.cinema_prev_focus.take() {
                self.ui.focused = prev;
            }
            ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(restore));
            return;
        }
        // A focused dock divider or floating-window grip takes the arrow keys to nudge it, but no
        // other key: Space and the other shortcuts keep working (#1482).
        let divider_focused = self.divider_focused(ctx);
        if (ctx.egui_wants_keyboard_input() && !divider_focused) || self.dialog == Some(Dialog::Shortcuts) || self.ui.clip_dialog.is_some() {
            return;
        }
        // A focused text field takes every unmodified key, including the ones our shortest
        // shortcuts use, so an input method can compose there (Vietnamese Telex, Korean, …; #243).
        // `egui_wants_keyboard_input` above is not enough: it is read before this pass lays the UI
        // out, so it still reports the previous pass, and it is true for any focused widget, which
        // would leave the editor without its single-key tool shortcuts while a slider has focus.
        let text_focused = ctx.text_edit_focused();
        // read before `input_mut`: the plugin lock must not be taken inside the input lock
        let label_selected = ctx.with_plugin(|s: &mut egui::text_selection::LabelSelectionState| s.has_selection()).unwrap_or(false);
        // Esc cancels a dynamic trim in progress
        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!({}));
        }
        panels::masks::pen_take_back(self, ctx, text_focused);
        let fire = ctx.input_mut(|i| self.match_shortcuts(i, text_focused, divider_focused, label_selected));
        self.fire_shortcuts(ctx, fire);
    }

    /// Key, text and clipboard events that a floating panel in its own OS window left over
    /// (`DockOutput::forwarded_events`): they run the main window's bindings in the frame they
    /// arrive, so shortcuts work while a floating window has focus. craft-ui forwards nothing
    /// while that window's text field has focus.
    pub(crate) fn handle_forwarded_keys(&mut self, ctx: &egui::Context, events: Vec<egui::Event>) {
        if events.is_empty() || self.dialog == Some(Dialog::Shortcuts) {
            return;
        }
        let mut input = egui::InputState::default();
        input.modifiers = self.floating_window_modifiers(ctx);
        input.events = events;
        if self.session.trim_play.dynamic.is_some() && input.consume_key(egui::Modifiers::NONE, egui::Key::Escape) {
            let _ = self.session.execute("trim.cancelDynamic", json!({}));
        }
        let fire = self.match_shortcuts(&mut input, false, false, false);
        self.fire_shortcuts(ctx, fire);
    }

    /// The modifiers held in the focused native floating window. Copy, Cut and Paste events
    /// carry none, and egui-winit drops the key press they stand for.
    fn floating_window_modifiers(&self, ctx: &egui::Context) -> egui::Modifiers {
        self.ui
            .dock
            .floating
            .iter()
            .filter(|window| window.native.is_some())
            .map(|window| craft_ui::docking::DockArea::<PanelKind>::window_viewport(dock_ui::area_id(), window.id))
            .find_map(|viewport| ctx.input_for(viewport, |i| (i.viewport().focused == Some(true)).then_some(i.modifiers)))
            .unwrap_or_default()
    }

    /// The binding ids the key presses in `i` fire, consuming those presses.
    fn match_shortcuts(&mut self, i: &mut egui::InputState, text_focused: bool, divider_focused: bool, label_selected: bool) -> Vec<String> {
        // Panel shortcuts of the focused panel override application shortcuts on the same chord.
        // A chord fires only with exactly its modifiers held (`menus::chord_held`), except that a
        // punctuation or digit key may carry the Shift or Alt a layout needs to type it, so the
        // most specific chords still go first across both scopes (the sort is stable, so the
        // panel still wins a tie). Before matching was exact, the Timeline's `Delete` (Clear)
        // swallowed the app-wide `Shift+Delete` (Ripple Delete) this way (#680).
        let focused = self.ui.focused.title();
        let mut fire = Vec::new();
        let modifiers = i.modifiers;
        // With no text on the system clipboard, egui-winit drops the Ctrl+V press but still
        // passes its release: put the press back, so Paste can paste files or an image (#611).
        let mut swallowed = None;
        for e in &i.events {
            match e {
                egui::Event::Key { key: egui::Key::V, pressed, modifiers: m, .. } => {
                    if !pressed && !self.v_down {
                        swallowed = Some(*m);
                    }
                    self.v_down = *pressed;
                }
                egui::Event::PasteImage(image) => {
                    // Keep the delivered pixels; re-reading the OS clipboard later is racy and
                    // the web host has no clipboard-media hook at all.
                    self.pasted_image = Some(image.clone());
                    if modifiers.command {
                        self.v_down = true;
                    }
                }
                egui::Event::Paste(_) if modifiers.command => self.v_down = true,
                _ => {}
            }
        }
        if let Some(m) = swallowed {
            i.events.push(egui::Event::Key {
                key: egui::Key::V,
                physical_key: Some(egui::Key::V),
                pressed: true,
                repeat: false,
                modifiers: m | egui::Modifiers::COMMAND,
            });
        }
        clipboard_events_as_keys(&mut i.events, modifiers, label_selected);
        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());
        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 {
            // With a text field focused, an unmodified key belongs to the field (and to the input
            // method composing in it), not to a tool shortcut: `J`, `Z`, `R`, `A`… are the keys
            // Vietnamese Telex combines into diacritics (#243). Chords with a modifier stay:
            // Ctrl+S and friends are not something a text field or an IME consumes.
            if lets_text_field_keep(*m, text_focused) {
                continue;
            }
            // The focused divider consumes the arrows itself, with or without Shift/Alt.
            if divider_focused && matches!(k, egui::Key::ArrowLeft | egui::Key::ArrowRight | egui::Key::ArrowUp | egui::Key::ArrowDown) {
                continue;
            }
            if consume_chord(i, *m, *k, repeats_when_held(id)) {
                fire.push(id.clone());
            }
        }
        fire
    }

    /// Run the commands of the bindings `match_shortcuts` fired, as the focused panel scopes them.
    fn fire_shortcuts(&mut self, ctx: &egui::Context, fire: Vec<String>) {
        for id in fire {
            // 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 {
                None
            };
            // Clear and Ripple Delete in Effect Controls never reach the clip (#1354). They remove the
            // selected effect, or the selected mask when no effect is selected; Motion and the other
            // fixed effects cannot be removed. A selection made on a clip the panel no longer shows
            // (clip A's effect selected, clip B selected in the Timeline) is stale and removes
            // nothing (#1400 review). With nothing removable selected the key is consumed and does
            // nothing, so a repeated Backspace cannot fall through to `edit.clear` and delete the
            // timeline clip. A transition shown in the panel is the exception: `edit.clear` removes
            // it, as it does from the Timeline, and Ripple Delete is consumed.
            if self.ui.focused == PanelKind::EffectControls && matches!(id.as_str(), "edit.clear" | "edit.rippleDelete") {
                // the clips the panel shows: the selected video clip and its linked audio clip, so a
                // selection on any row the panel displays is removable
                let shown = crate::panels::effect_controls::selected_clips(self);
                let remove = match (&self.session.state.selected_effect, &self.session.state.selected_mask) {
                    (Some(e), _) if shown.iter().any(|(c, _, _)| *c == e.clip) => self.session.active_sequence().and_then(|s| {
                        let (_, it) = s.find_item(e.clip)?;
                        let idx = e.index(&it.effects)?;
                        if it.effects.get(idx)?.def().is_some_and(|d| d.intrinsic) {
                            None
                        } else {
                            Some(("effects.remove", json!({"clip": e.clip.0, "index": idx})))
                        }
                    }),
                    (None, Some(m)) if shown.iter().any(|(c, _, _)| *c == m.clip) => {
                        Some(("masks.remove", json!({"clip": m.clip.0, "effect": m.effect, "mask": m.mask})))
                    }
                    _ => None,
                };
                // no clip shown: the panel displays a selected transition (#430), and `edit.clear`
                // removes it exactly as from the Timeline; Ripple Delete stays consumed
                let remove = remove.or_else(|| {
                    (id == "edit.clear" && shown.is_empty() && crate::panels::transition_controls::selected(self).is_some()).then(|| ("edit.clear", json!({})))
                });
                if let Some((cmd, params)) = remove
                    && let Err(e) = menus::invoke(self, ctx, cmd, params)
                {
                    self.ui.status = e;
                }
                continue;
            }
            // Mark In/Out in the Source monitor when it has focus.
            let params = if let Some(p) = clear {
                p
            } else if self.ui.focused == PanelKind::Source
                && (matches!(id.as_str(), "markers.markIn" | "markers.markOut" | "markers.clearInOut")
                    || id.starts_with("markers.markSplit")
                    || id.starts_with("markers.goToSplit"))
            {
                json!({"target": "source"})
            } else {
                json!({})
            };
            if let Err(e) = menus::invoke(self, ctx, &id, params) {
                self.ui.status = e;
            }
        }
        // Only the paste action of this pass may consume the event's image.
        self.pasted_image = None;
    }
}

/// The windowing layer (egui-winit, and egui's web backend) reports the clipboard shortcuts as
/// `Event::Copy` / `Event::Cut` / `Event::Paste` instead of key presses: Ctrl+C/X/V on Windows and
/// Linux, plus Ctrl+Insert, Shift+Insert and Shift+Delete on Windows. The shortcut bindings only
/// match key presses, so Copy, Cut, Paste, Paste Insert, Paste Attributes and (on Windows) Ripple
/// Delete never fired from the keyboard (#199). macOS was unaffected because its native menu bar
/// takes the key equivalents first.
///
/// Add the key press each event stands for, with the modifiers held, so the bindings see it. The
/// original event stays for anything else that reads it. Only called when no text field has
/// keyboard focus; text fields keep handling the clipboard themselves. Selected label text (a
/// status bar message, #2295) keeps Copy and Cut the same way: Ctrl+C copies the text, not the
/// selected clips.
fn clipboard_events_as_keys(events: &mut Vec<egui::Event>, modifiers: egui::Modifiers, label_selected: bool) {
    use egui::{Event, Key};
    let keys: Vec<Key> = events
        .iter()
        .filter_map(|e| match e {
            Event::Copy | Event::Cut if label_selected => None,
            Event::Copy if modifiers.command => Some(Key::C),
            Event::Copy => Some(Key::Copy),
            Event::Cut if modifiers.command => Some(Key::X),
            Event::Cut if modifiers.shift => Some(Key::Delete),
            Event::Cut => Some(Key::Cut),
            Event::Paste(_) | Event::PasteImage(_) if modifiers.command => Some(Key::V),
            Event::Paste(_) | Event::PasteImage(_) if modifiers.shift => Some(Key::Insert),
            Event::Paste(_) | Event::PasteImage(_) => Some(Key::Paste),
            _ => None,
        })
        .collect();
    events.extend(keys.into_iter().map(|key| Event::Key { key, physical_key: Some(key), pressed: true, repeat: false, modifiers }));
}

/// Whether holding a shortcut's key repeats the command. Transport commands start, stop or
/// toggle playback, so the OS key repeats of a held Space would flip Play/Stop many times a
/// second; they run once per press. Stepping, nudging and the rest keep repeating.
fn repeats_when_held(id: &str) -> bool {
    !(id.starts_with("playback.") || id.starts_with("source.playback."))
}

/// Like `InputState::consume_key`, but the held modifiers must be exactly the chord's
/// (`menus::chord_held`): egui's `consume_key` ignores extra modifiers, so Ctrl+Alt+Cmd+N ran
/// File ▸ New ▸ Project (Cmd+Alt+N). Every press of the chord is consumed; it fires on key repeats
/// too when `repeats`, else only on a fresh press, and the repeats are still consumed so they
/// can't reach a less specific binding.
fn consume_chord(i: &mut egui::InputState, modifiers: egui::Modifiers, key: egui::Key, repeats: bool) -> bool {
    let mut fires = false;
    i.events.retain(|e| match e {
        egui::Event::Key { key: k, modifiers: m, pressed: true, repeat, .. } if *k == key && menus::chord_held(*m, *k, modifiers) => {
            fires |= repeats || !repeat;
            false
        }
        _ => true,
    });
    fires
}

/// Whether a shortcut chord must be left alone because a text field is focused.
///
/// A focused text field owns every unmodified key: an input method composes there from plain
/// letters (Vietnamese Telex builds `á` from `a` + `s`, `ả` from `a` + `r`, `ạ` from `a` + `j`),
/// and our single-key tool shortcuts would swallow them before the field sees them (#243). Chords
/// with a modifier are not what a text field or an IME consumes, so they keep working.
fn lets_text_field_keep(modifiers: egui::Modifiers, text_focused: bool) -> bool {
    text_focused && menus::specificity(modifiers) == 0
}

#[cfg(test)]
mod clipboard_key_tests {
    use egui::{Event, Key, Modifiers};

    fn keys(events: Vec<Event>, m: Modifiers) -> Vec<(Key, Modifiers)> {
        let mut events = events;
        super::clipboard_events_as_keys(&mut events, m, false);
        events.into_iter().filter_map(|e| if let Event::Key { key, modifiers, pressed: true, .. } = e { Some((key, modifiers)) } else { None }).collect()
    }

    /// Clipboard Copy/Cut/Paste events become C/X/V key presses so they match the shortcut bindings.
    #[test]
    fn ctrl_c_x_v_become_key_presses() {
        let c = Modifiers::COMMAND;
        assert_eq!(keys(vec![Event::Copy], c), vec![(Key::C, c)]);
        assert_eq!(keys(vec![Event::Cut], c), vec![(Key::X, c)]);
        assert_eq!(keys(vec![Event::Paste("x".into())], c), vec![(Key::V, c)]);
        let image = || Event::PasteImage(std::sync::Arc::new(egui::ColorImage::filled([1, 1], egui::Color32::RED)));
        assert_eq!(keys(vec![image()], c), vec![(Key::V, c)]);
        assert_eq!(keys(vec![image()], Modifiers::SHIFT), vec![(Key::Insert, Modifiers::SHIFT)]);
        assert_eq!(keys(vec![image()], Modifiers::NONE), vec![(Key::Paste, Modifiers::NONE)]);
    }

    #[test]
    fn extra_modifiers_are_kept() {
        // Paste Insert (Ctrl+Shift+V) and Paste Attributes (Ctrl+Alt+V) also arrive as Paste
        let cs = Modifiers::COMMAND | Modifiers::SHIFT;
        assert_eq!(keys(vec![Event::Paste("x".into())], cs), vec![(Key::V, cs)]);
        let ca = Modifiers::COMMAND | Modifiers::ALT;
        assert_eq!(keys(vec![Event::Paste("x".into())], ca), vec![(Key::V, ca)]);
    }

    #[test]
    fn windows_insert_and_delete_variants() {
        // Shift+Delete (Ripple Delete) arrives as Cut on Windows; Shift+Insert as Paste
        assert_eq!(keys(vec![Event::Cut], Modifiers::SHIFT), vec![(Key::Delete, Modifiers::SHIFT)]);
        assert_eq!(keys(vec![Event::Paste("x".into())], Modifiers::SHIFT), vec![(Key::Insert, Modifiers::SHIFT)]);
    }

    #[test]
    fn other_events_are_left_alone() {
        let mut events = vec![Event::Text("a".into()), Event::Copy];
        super::clipboard_events_as_keys(&mut events, Modifiers::COMMAND, false);
        assert_eq!(events.len(), 3);
        assert!(matches!(events[0], Event::Text(_)));
        assert!(matches!(events[1], Event::Copy));
    }

    #[test]
    fn selected_label_text_keeps_copy_and_cut() {
        let c = Modifiers::COMMAND;
        let mut events = vec![Event::Copy, Event::Cut, Event::Paste("x".into())];
        super::clipboard_events_as_keys(&mut events, c, true);
        let keys: Vec<Key> = events.iter().filter_map(|e| if let Event::Key { key, .. } = e { Some(*key) } else { None }).collect();
        assert_eq!(keys, vec![Key::V], "only Paste becomes a key press");
        assert!(matches!(events[0], Event::Copy), "the selection still gets the Copy event");
    }
}

#[cfg(test)]
mod forwarded_key_tests {
    use egui::{Event, Key, Modifiers};

    /// A key a floating native window left over runs the main window's bindings.
    #[test]
    fn forwarded_keys_fire_shortcuts() {
        let mut app = super::FilmcraftApp::new(filmcraft_engine::Session::default());
        app.bindings = super::menus::bindings(&app);
        app.ui.focused = crate::dock::PanelKind::Timeline;
        let shift_backtick = Event::Key { key: Key::Backtick, physical_key: Some(Key::Backtick), pressed: true, repeat: false, modifiers: Modifiers::SHIFT };
        app.handle_forwarded_keys(&egui::Context::default(), vec![Event::Text("~".into()), shift_backtick]);
        assert_eq!(app.ui.keys.maximized, Some(crate::dock::PanelKind::Timeline), "Shift+` maximizes the focused frame");
    }
}

#[cfg(test)]
mod text_focus_shortcut_tests {
    use super::lets_text_field_keep;
    use egui::{Key, Modifiers};

    /// Vietnamese Telex composes diacritics from unmodified letters (`a` + `s` → `á`, `a` + `r` →
    /// `ả`, `a` + `j` → `ạ`), and the editor binds `J`, `Z`, `R`, `A`, `C`, `T`, `K`, `L`, `B`, `N`,
    /// `P`, `V`, `Y`, `U`, `H` as single-key tool shortcuts. While a text field is focused those
    /// keys must reach the field, or no diacritic can ever be typed (#243).
    #[test]
    fn an_unmodified_key_reaches_a_focused_text_field() {
        assert!(lets_text_field_keep(Modifiers::NONE, true), "the IME needs the plain letter keys");
    }

    /// Without a text field the editor keeps its single-key tool shortcuts.
    #[test]
    fn an_unmodified_key_still_fires_without_a_text_field() {
        assert!(!lets_text_field_keep(Modifiers::NONE, false));
    }

    /// A modifier chord is not what a text field or an IME consumes, so it keeps firing either way.
    #[test]
    fn a_modified_chord_still_fires_while_text_is_focused() {
        for m in [Modifiers::COMMAND, Modifiers::CTRL, Modifiers::SHIFT, Modifiers::ALT, Modifiers::COMMAND | Modifiers::SHIFT] {
            assert!(!lets_text_field_keep(m, true), "{m:?} is not an IME key");
        }
    }

    /// The keys a Vietnamese Telex IME needs must be exactly the ones we now hand to the field.
    #[test]
    fn the_telex_trigger_keys_are_left_to_the_field() {
        // s=acute, f=grave, r=hook above, x=tilde, j=dot below, w=horn, z=remove diacritic
        for key in [Key::S, Key::F, Key::R, Key::X, Key::J, Key::W, Key::Z] {
            assert!(lets_text_field_keep(Modifiers::NONE, true), "{key:?} must reach the IME");
        }
        // The letters the editor binds as tools are the ones Telex composes with, so they must be
        // left to the field too: `A` (Track Select Forward), `R` (Rate Stretch), `J` (Shuttle Left),
        // `Z` (Zoom), `C` (Razor), `T` (Type).
        for key in [Key::A, Key::R, Key::J, Key::Z, Key::C, Key::T] {
            assert!(lets_text_field_keep(Modifiers::NONE, true), "{key:?} is a Telex key the tools stole");
        }
    }
}

#[cfg(test)]
mod key_repeat_tests {
    use egui::{Event, Key, Modifiers};

    fn space(repeat: bool, modifiers: Modifiers) -> Event {
        Event::Key { key: Key::Space, physical_key: Some(Key::Space), pressed: true, repeat, modifiers }
    }

    fn fired(events: Vec<Event>) -> Vec<String> {
        let mut app = super::FilmcraftApp::new(filmcraft_engine::Session::default());
        app.bindings = super::menus::bindings(&app);
        app.ui.focused = crate::dock::PanelKind::Timeline;
        let mut input = egui::InputState::default();
        input.events = events;
        app.match_shortcuts(&mut input, false, false, false)
    }

    /// Holding Space sends one press and then OS key repeats: Play/Stop runs once, not once per
    /// repeat, or playback flickers between playing and paused.
    #[test]
    fn held_space_toggles_playback_once() {
        assert_eq!(fired(vec![space(false, Modifiers::NONE), space(true, Modifiers::NONE), space(true, Modifiers::NONE)]), ["playback.toggle"]);
        assert!(fired(vec![space(true, Modifiers::NONE), space(true, Modifiers::NONE)]).is_empty(), "repeats alone start nothing");
    }

    /// A repeat of Shift+Space is swallowed, not handed down to the plain Space binding.
    #[test]
    fn held_shift_space_does_not_fall_through_to_play_stop() {
        assert!(fired(vec![space(true, Modifiers::SHIFT)]).is_empty());
    }

    /// Frame stepping is meant to be held: its repeats keep firing.
    #[test]
    fn held_arrow_keeps_stepping() {
        let right = |repeat| Event::Key { key: Key::ArrowRight, physical_key: Some(Key::ArrowRight), pressed: true, repeat, modifiers: Modifiers::NONE };
        assert_eq!(fired(vec![right(false), right(true)]).len(), 1, "one pass consumes every press of the chord");
        assert_eq!(fired(vec![right(true)]), ["playhead.stepForward"]);
    }
}

#[cfg(test)]
mod exact_modifier_tests {
    use crate::dock::PanelKind;
    use egui::{Event, Key, Modifiers};

    /// What the window reports for Cmd: `mac_cmd` too on a Mac; off a Mac the Ctrl key, which
    /// carries `ctrl` as well (#245).
    fn cmd() -> Modifiers {
        if cfg!(target_os = "macos") { Modifiers::MAC_CMD | Modifiers::COMMAND } else { Modifiers::CTRL | Modifiers::COMMAND }
    }

    /// The binding ids one fresh press of `key` with `modifiers` fires, `panel` focused.
    fn fired(panel: PanelKind, key: Key, modifiers: Modifiers) -> Vec<String> {
        let mut app = super::FilmcraftApp::new(filmcraft_engine::Session::default());
        app.bindings = super::menus::bindings(&app);
        app.ui.focused = panel;
        let mut input = egui::InputState::default();
        input.modifiers = modifiers;
        input.events = vec![Event::Key { key, physical_key: Some(key), pressed: true, repeat: false, modifiers }];
        app.match_shortcuts(&mut input, false, false, false)
    }

    /// The bug: on a Mac, Ctrl+Opt+Cmd+N ran File ▸ New ▸ Project (Cmd+Opt+N) and its "discard
    /// the open project" path, because egui ignores an extra Control when matching a Cmd chord.
    /// The native menu bar matches key equivalents exactly, so the press reached these bindings.
    #[test]
    fn ctrl_alt_cmd_n_does_not_run_new_project() {
        if cfg!(target_os = "macos") {
            assert!(fired(PanelKind::Timeline, Key::N, cmd() | Modifiers::ALT | Modifiers::CTRL).is_empty());
        }
        assert!(fired(PanelKind::Timeline, Key::N, cmd() | Modifiers::ALT | Modifiers::SHIFT).is_empty(), "nor Cmd+Alt+Shift+N");
    }

    #[test]
    fn cmd_alt_n_still_runs_new_project() {
        assert_eq!(fired(PanelKind::Timeline, Key::N, cmd() | Modifiers::ALT), ["file.newProject"]);
        assert_eq!(fired(PanelKind::Timeline, Key::N, cmd()), ["file.newSequence"]);
    }

    /// An unbound chord with an extra modifier runs nothing instead of a shorter binding.
    #[test]
    fn an_extra_modifier_does_not_fall_through_to_a_shorter_chord() {
        assert!(fired(PanelKind::Timeline, Key::N, cmd() | Modifiers::SHIFT).is_empty(), "Cmd+Shift+N is not New Sequence");
        assert!(fired(PanelKind::Timeline, Key::Space, Modifiers::ALT).is_empty(), "Alt+Space is not Play/Stop");
    }

    /// Chords that name more modifiers still win over the shorter ones on the same key.
    #[test]
    fn specific_chords_still_win() {
        assert_eq!(fired(PanelKind::Timeline, Key::Delete, Modifiers::SHIFT), ["edit.rippleDelete"], "not the Timeline's Clear (#680)");
        assert_eq!(fired(PanelKind::Timeline, Key::Delete, Modifiers::NONE), ["edit.clear"]);
        assert_eq!(fired(PanelKind::Timeline, Key::L, Modifiers::SHIFT), ["playback.slowForward"], "Shift+L shuttles slowly");
        assert_eq!(fired(PanelKind::Timeline, Key::Space, Modifiers::SHIFT), ["playback.inToOutPreroll"]);
    }

    /// Shifted punctuation keeps working: Shift+; arrives as `:`, and Cmd+Shift+= (the `+` key on
    /// US layouts) does what Cmd+= does (#2253).
    #[test]
    fn shifted_punctuation_still_matches() {
        assert_eq!(fired(PanelKind::Timeline, Key::Colon, Modifiers::SHIFT), ["sequence.goToNextGap"]);
        let equals = fired(PanelKind::Timeline, Key::Equals, cmd());
        assert_eq!(equals, ["timeline.increaseVideoHeight"]);
        assert_eq!(fired(PanelKind::Timeline, Key::Plus, cmd() | Modifiers::SHIFT), equals);
        assert_eq!(fired(PanelKind::Timeline, Key::Plus, cmd()), equals);
    }
}