forge
Explore
Log in

Don't you dare go Hollow

A card no longer swallows undo, redo, save or the clipboard

Browse files at this commit

35306fd4b2238117c88e8fa69f67d44749fe43b6Ahmet Kaan GümüşParent: 19dcc3e
  • fix
    • a card no longer swallows undo, redo, save or the clipboard
Show full message
🐛 fix(keys): a card no longer swallows undo, redo, save or the clipboard

`param_card_key` answers `true` for every stroke once one of the seven param cards is open, so `ctrl+z`, `ctrl+y`, `ctrl+s`, `ctrl+c` and `ctrl+v` never reached `keymap.lookup` at all -- the equalizer card's own comment says undo was always meant to be undo's own key ("Nothing to undo: every change is already at the clip, and undo is undo's own key").

`card_safe_action` names the five chords that act on the document rather than on the card, and the root handler dispatches them ahead of the cards' own branches and ahead of the blanket modal guard. The list is asked through the keymap, so a rebind moves the chord and this follows it. Escape, the arrows, `m`, the digits and the bare card letters stay the cards' own strokes.
crates/app/src/tests/view.rsmodified+90 -2
@@ -891,7 +891,7 @@ fn the_zoom_button_says_how_much_is_on_the_bed() {
891 /// lives.891 /// lives.
892 #[test]892 #[test]
893 fn tab_cycles_dock_bench_inspector_and_wraps() {893 fn tab_cycles_dock_bench_inspector_and_wraps() {
894- use crate::ui::stance::{Surface, next_surface};894+ use crate::ui::stance::{next_surface, Surface};
895 895
896 assert_eq!(next_surface(Surface::Dock, false), Surface::Bench);896 assert_eq!(next_surface(Surface::Dock, false), Surface::Bench);
897 assert_eq!(next_surface(Surface::Bench, false), Surface::Inspector);897 assert_eq!(next_surface(Surface::Bench, false), Surface::Inspector);
@@ -912,7 +912,7 @@ fn tab_cycles_dock_bench_inspector_and_wraps() {
912 /// surface being entered is always the one mounted.912 /// surface being entered is always the one mounted.
913 #[test]913 #[test]
914 fn surface_wants_src_active_mounts_the_tab_before_focus_lands_on_it() {914 fn surface_wants_src_active_mounts_the_tab_before_focus_lands_on_it() {
915- use crate::ui::stance::{Surface, surface_wants_src_active};915+ use crate::ui::stance::{surface_wants_src_active, Surface};
916 916
917 assert_eq!(surface_wants_src_active(Surface::Dock), Some(true));917 assert_eq!(surface_wants_src_active(Surface::Dock), Some(true));
918 assert_eq!(surface_wants_src_active(Surface::Inspector), Some(false));918 assert_eq!(surface_wants_src_active(Surface::Inspector), Some(false));
@@ -976,3 +976,91 @@ fn focus_panels_is_bound_and_lands_on_the_dock() {
976 // have stolen it.976 // have stolen it.
977 assert_eq!(k.lookup("tab", false), Some(ActionId::Select));977 assert_eq!(k.lookup("tab", false), Some(ActionId::Select));
978 }978 }
979+
980+/// A card is not a key-eating black box: the room-wide chords that act on the
981+/// document -- the edit history, the project file, the clipboard -- must reach
982+/// `Player::act` while any card is open. `param_card_key` answers `true` for
983+/// *every* stroke once one of the seven is up, so the dispatch has to stand in
984+/// front of it, not only in front of the blanket modal guard under it; and the
985+/// blanket guard's own `card_open()` has to read after that dispatch too, or a
986+/// chord that got past `param_card_key` (a menu dismiss comes to mind) would
987+/// still never reach the keymap.
988+///
989+/// A scan of the handler's own source, for the reason every handler scan here
990+/// gives: this binary has no window harness to press `ctrl+z` through.
991+#[test]
992+fn an_open_card_does_not_swallow_the_document_chords() {
993+ use crate::ui::stance::card_safe_action;
994+ use keymap::ActionId;
995+ // The five the room answers through a card, and the reason each is on the
996+ // list: history, file, clipboard.
997+ for action in [
998+ ActionId::Undo,
999+ ActionId::Redo,
1000+ ActionId::Save,
1001+ ActionId::Copy,
1002+ ActionId::Paste,
1003+ ] {
1004+ assert!(
1005+ card_safe_action(action),
1006+ "{action:?} is a document chord and a card must not eat it"
1007+ );
1008+ }
1009+ // ...and the strokes the cards' own branch list claims stay theirs:
1010+ // escape is every card's way out, `s` is the equalizer's spectrum, `x` its
1011+ // band removal, `m` every card's maximize, and the digits pick a band.
1012+ for action in [
1013+ ActionId::Deselect,
1014+ ActionId::Cut,
1015+ ActionId::Delete,
1016+ ActionId::ToggleMute,
1017+ ActionId::Equalizer,
1018+ ActionId::Color,
1019+ ActionId::Loop,
1020+ ActionId::TrimIn,
1021+ ] {
1022+ assert!(
1023+ !card_safe_action(action),
1024+ "{action:?} is a card's own stroke and the card must keep it"
1025+ );
1026+ }
1027+ // The chords are real bindings, not a list of actions nothing reaches.
1028+ let keys = keymap::Keymap::defaults();
1029+ for (key, ctrl, action) in [
1030+ ("z", true, ActionId::Undo),
1031+ ("y", true, ActionId::Redo),
1032+ ("s", true, ActionId::Save),
1033+ ("c", true, ActionId::Copy),
1034+ ("v", true, ActionId::Paste),
1035+ ] {
1036+ assert_eq!(
1037+ keys.lookup(key, ctrl),
1038+ Some(action),
1039+ "the keymap no longer binds {action:?}"
1040+ );
1041+ }
1042+ // And the dispatch stands where it has to: inside the root handler, ahead
1043+ // of the cards' own branches and ahead of the blanket modal guard.
1044+ let stance_rs = src_text("ui/stance.rs");
1045+ let dispatch = stance_rs.find("card_safe_action(action)").expect(
1046+ "the root key handler no longer asks which chords a card does not take -- an open card \
1047+ eats every stroke again",
1048+ );
1049+ assert!(
1050+ stance_rs[..dispatch].contains("this.keymap.lookup(key, ctrl)"),
1051+ "the dispatch no longer goes through the keymap, so a rebind would leave it behind"
1052+ );
1053+ for (guard, label) in [
1054+ ("if this.param_card_key(", "the cards' own key branches"),
1055+ ("if this.card_open()", "the blanket modal guard"),
1056+ ] {
1057+ let at = stance_rs
1058+ .find(guard)
1059+ .unwrap_or_else(|| panic!("{label} moved or was renamed"));
1060+ assert!(
1061+ dispatch < at,
1062+ "{label} reads before the document dispatch -- an open card would \
1063+ swallow undo, redo, save and the clipboard pair again"
1064+ );
1065+ }
1066+}
crates/app/src/ui/stance.rsmodified+74 -0
@@ -68,6 +68,55 @@ pub(crate) fn is_focus_exit_key(key: &str) -> bool {
68 key == "escape"68 key == "escape"
69 }69 }
70 70
71+/// The room-wide chords an open card does not take.
72+///
73+/// A card owns the keyboard for its own *values* -- the arrows on a slider, `r`
74+/// for reset, `m` for maximize, the digits on the equalizer, `enter` to apply
75+/// ([`Player::param_card_key`]'s branch list) -- and every one of those is a
76+/// *bare* stroke its own branch claims. These five are not: each acts on the
77+/// document rather than on the card the hand is looking at, and while a card is
78+/// open the room must still answer them. It is the equalizer card's own comment
79+/// that says so from the inside: "Nothing to undo: every change is already at
80+/// the clip, and undo is undo's own key".
81+///
82+/// - `Undo`/`Redo`: the edit history. The one chord a hand reaches for *while*
83+/// looking at what it just changed, which is exactly when a card is open.
84+/// - `Save`: the project file. Its chord is `ctrl+s`, and no card's branch
85+/// answers a ctrl chord on purpose (`param_card_key` is handed the shift
86+/// modifier alone).
87+/// - `Copy`/`Paste`: the clip clipboard, the pair beside the history keys.
88+///
89+/// Asked against the [`keymap::ActionId`] the stroke resolved to, never against
90+/// a key literal: a rebind moves the chord and this list follows it.
91+///
92+/// Deliberately *not* here, in three kinds:
93+///
94+/// 1. The strokes a card's own branch list claims, which the card must keep:
95+/// escape (every card's way out, and `Deselect`'s own stroke), the arrows
96+/// (`StepBack`/`StepForward`/`JumpBack`/`JumpForward` -- the branch reads
97+/// them with or without ctrl), `m` (`ToggleMute`) and the digits, plus the
98+/// bare letters the cards' verbs sit on -- `r` (`Loop`, `Resolution`), `f`
99+/// (`Mix`, `Crossfade`), `a` (`AddAudioLane`, `SelectAll`), `s`
100+/// (`Cut` -- the EQ card's spectrum), `x` (`Delete`, `Dissolve` -- the
101+/// band's removal), `k` (`Color`), `j`, `u`, `y` (`SubtitleStyle`), `enter`
102+/// (the silence card's apply).
103+/// 2. The chords that open a card: `Export`/`Settings`/`Color`/`Transform`/
104+/// `Speed`/`Silence`/`Mix`/`Equalizer`/`SubtitleStyle`. They own the very
105+/// modal slot the open card is sitting in, and swapping the surface under a
106+/// hand mid-stroke is not a chord this fix is for.
107+/// 3. Everything else the keymap binds (the odometer, the trims, the zoom, the
108+/// lane add/remove pair, the theme, the screenshot...). They are left to the
109+/// card on purpose, the way [`Player::param_card_key`] left them before this:
110+/// the defect is a card swallowing the *history* while the user edits through
111+/// it, and each of these is one press away again the moment the card closes.
112+pub(crate) fn card_safe_action(action: crate::keymap::ActionId) -> bool {
113+ use crate::keymap::ActionId;
114+ matches!(
115+ action,
116+ ActionId::Undo | ActionId::Redo | ActionId::Save | ActionId::Copy | ActionId::Paste
117+ )
118+}
119+
71 /// The dock mounts only one of its two tabs at a time120 /// The dock mounts only one of its two tabs at a time
72 /// (`dock_stance::render`'s `match src_active`), so `focus_dock` only has a121 /// (`dock_stance::render`'s `match src_active`), so `focus_dock` only has a
73 /// tree node under Sources and `focus_inspector` only under Clip -- focusing122 /// tree node under Sources and `focus_inspector` only under Clip -- focusing
@@ -1068,6 +1117,25 @@ pub(crate) fn render(
1068 cx.notify();1117 cx.notify();
1069 return;1118 return;
1070 }1119 }
1120+ // A card is not a key-eating black box. The room-wide chords that
1121+ // act on the document rather than on the card -- the edit history,
1122+ // the project file, the clipboard ([`card_safe_action`]) -- run
1123+ // here, ahead of the cards' own key branches below and ahead of the
1124+ // blanket modal guard under them, so an open card cannot swallow
1125+ // the stroke a hand reaches for while looking at what it changed.
1126+ // `param_card_key` answers `true` for every stroke once a card is
1127+ // open, so this has to stand in front of *it*, not only in front of
1128+ // the guard: `ctrl+z` never reached `keymap.lookup` at all, and the
1129+ // card's own comment says undo was always meant to be undo's key.
1130+ //
1131+ // Asked through the keymap rather than as a table of key literals:
1132+ // a rebind moves the chord and this follows.
1133+ if let Some(action) = this.keymap.lookup(key, ctrl)
1134+ && card_safe_action(action)
1135+ {
1136+ this.act(action, window, cx);
1137+ return;
1138+ }
1071 // The param cards' own key branches (arrows nudge the focused1139 // The param cards' own key branches (arrows nudge the focused
1072 // slider, digits pick an EQ band, `r` resets, card verbs) --1140 // slider, digits pick an EQ band, `r` resets, card verbs) --
1073 // `Player::param_card_key` (`player/cards.rs`), the same1141 // `Player::param_card_key` (`player/cards.rs`), the same
@@ -1125,6 +1193,12 @@ pub(crate) fn render(
1125 // clip_menu/row_menu/list chain follows (`render.rs`): this is1193 // clip_menu/row_menu/list chain follows (`render.rs`): this is
1126 // the fix for "no state may make the room modal without1194 // the fix for "no state may make the room modal without
1127 // showing anything", not only the source-dot's menu.1195 // showing anything", not only the source-dot's menu.
1196+ //
1197+ // Except the document chords, which were answered *above* and
1198+ // left the menu standing: a menu is a visible surface with
1199+ // escape and any other key still shutting it, and losing an
1200+ // undo to a square of the screen a right-click left open would
1201+ // be the black box this handler no longer is.
1128 this.context_menu = None;1202 this.context_menu = None;
1129 this.library_menu = None;1203 this.library_menu = None;
1130 this.picker = None;1204 this.picker = None;