forge
Explore
Log in

Don't you dare go Hollow

Escape clears the selection

Browse files at this commit

eeba459441c2568bb92dde29178ced7aa9431211Ahmet Kaan GümüşParent: 7f34c17842cc98
  • feat
    • escape clears the selection
Show full message
✨ feat(keymap): escape clears the selection
crates/app/src/keymap.rsmodified+13 -3
@@ -118,6 +118,9 @@ actions! {
118 /// ctrl-click that builds a selection by hand, for the times everything118 /// ctrl-click that builds a selection by hand, for the times everything
119 /// wants selecting at once.119 /// wants selecting at once.
120 SelectAll,120 SelectAll,
121+ /// Bare escape with nothing else claiming it: empties a multi-clip
122+ /// selection without touching picks, cards or fullscreen.
123+ Deselect,
121 Delete,124 Delete,
122 Lift,125 Lift,
123 Color,126 Color,
@@ -256,6 +259,7 @@ impl ActionId {
256 ActionId::SelectNext => "Select the next clip in the lane",259 ActionId::SelectNext => "Select the next clip in the lane",
257 ActionId::SelectPrev => "Select the previous clip in the lane",260 ActionId::SelectPrev => "Select the previous clip in the lane",
258 ActionId::SelectAll => "Select everything (every clip and caption)",261 ActionId::SelectAll => "Select everything (every clip and caption)",
262+ ActionId::Deselect => "Clear the selection",
259 ActionId::Delete => "Delete",263 ActionId::Delete => "Delete",
260 ActionId::Lift => "Lift (leave a gap)",264 ActionId::Lift => "Lift (leave a gap)",
261 ActionId::Color => "Colour…",265 ActionId::Color => "Colour…",
@@ -335,6 +339,7 @@ impl ActionId {
335 ActionId::SelectNext => "select-next",339 ActionId::SelectNext => "select-next",
336 ActionId::SelectPrev => "select-prev",340 ActionId::SelectPrev => "select-prev",
337 ActionId::SelectAll => "select-all",341 ActionId::SelectAll => "select-all",
342+ ActionId::Deselect => "deselect",
338 ActionId::Delete => "delete",343 ActionId::Delete => "delete",
339 ActionId::Lift => "lift",344 ActionId::Lift => "lift",
340 ActionId::Color => "color",345 ActionId::Color => "color",
@@ -413,6 +418,7 @@ impl ActionId {
413 | ActionId::SelectNext418 | ActionId::SelectNext
414 | ActionId::SelectPrev419 | ActionId::SelectPrev
415 | ActionId::SelectAll420 | ActionId::SelectAll
421+ | ActionId::Deselect
416 | ActionId::Delete422 | ActionId::Delete
417 | ActionId::Lift423 | ActionId::Lift
418 | ActionId::Color424 | ActionId::Color
@@ -1055,6 +1061,10 @@ impl Keymap {
1055 // below had to move off ctrl+a: a stroke that universal was1061 // below had to move off ctrl+a: a stroke that universal was
1056 // never really the removal's to keep.1062 // never really the removal's to keep.
1057 b(ActionId::SelectAll, "a", true),1063 b(ActionId::SelectAll, "a", true),
1064+ // Bare escape, last in the precedence chain behind every card,
1065+ // search and fullscreen close (render.rs) -- just empties the
1066+ // selection when nothing else claims the key.
1067+ b(ActionId::Deselect, "escape", false),
1058 b(ActionId::Delete, "x", false),1068 b(ActionId::Delete, "x", false),
1059 b(ActionId::Delete, "delete", false),1069 b(ActionId::Delete, "delete", false),
1060 b(ActionId::Lift, "l", false),1070 b(ActionId::Lift, "l", false),
@@ -1500,7 +1510,7 @@ mod tests {
1500 #[test]1510 #[test]
1501 fn every_default_stroke_reaches_its_action() {1511 fn every_default_stroke_reaches_its_action() {
1502 let k = Keymap::defaults();1512 let k = Keymap::defaults();
1503- assert_eq!(k.entries().len(), 74);1513+ assert_eq!(k.entries().len(), 75);
1504 // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+.1514 // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+.
1505 // actually type) strides ten.1515 // actually type) strides ten.
1506 assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext));1516 assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext));
@@ -1584,9 +1594,9 @@ mod tests {
1584 assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp));1594 assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp));
1585 assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown));1595 assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown));
1586 assert_eq!(k.lookup("+", false), None);1596 assert_eq!(k.lookup("+", false), None);
1587- // The chord, and *only* the chord: bare escape reaches no action at all.1597+ // The chord cancels an export; bare escape falls through to Deselect.
1588 assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport));1598 assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport));
1589- assert_eq!(k.lookup("escape", false), None);1599+ assert_eq!(k.lookup("escape", false), Some(ActionId::Deselect));
1590 // The modifier is half the chord: ctrl+e is not e.1600 // The modifier is half the chord: ctrl+e is not e.
1591 assert_eq!(k.lookup("e", true), None);1601 assert_eq!(k.lookup("e", true), None);
1592 assert_eq!(k.lookup("space", true), None);1602 assert_eq!(k.lookup("space", true), None);
crates/app/src/player/actions.rsmodified+6 -0
@@ -98,6 +98,12 @@ impl Player {
98 ActionId::SelectNext => self.select_step(true, cx),98 ActionId::SelectNext => self.select_step(true, cx),
99 ActionId::SelectPrev => self.select_step(false, cx),99 ActionId::SelectPrev => self.select_step(false, cx),
100 ActionId::SelectAll => self.select_all(cx),100 ActionId::SelectAll => self.select_all(cx),
101+ // Last in escape's precedence chain (render.rs): nothing else
102+ // claimed the key, so it just empties the selection.
103+ ActionId::Deselect => {
104+ self.selected = Selection::new();
105+ cx.notify();
106+ }
101 ActionId::Delete => self.delete_selected(cx),107 ActionId::Delete => self.delete_selected(cx),
102 ActionId::Lift => self.lift_selected(cx),108 ActionId::Lift => self.lift_selected(cx),
103 ActionId::Color => self.open_color(cx),109 ActionId::Color => self.open_color(cx),
crates/app/src/tests/cards.rsmodified+3 -2
@@ -187,8 +187,9 @@ fn only_a_chord_gets_out_of_an_export() {
187 assert!(!cancels_export("e", false, Some(ActionId::Export)));187 assert!(!cancels_export("e", false, Some(ActionId::Export)));
188 assert!(!cancels_export("space", false, Some(ActionId::Play)));188 assert!(!cancels_export("space", false, Some(ActionId::Play)));
189 assert!(!cancels_export("q", false, None));189 assert!(!cancels_export("q", false, None));
190- // The default keymap is what the handler feeds this: the chord reaches the190+ // The default keymap is what the handler feeds this: the chord reaches
191- // action, the bare key reaches nothing.191+ // CancelExport, the bare key reaches Deselect instead -- neither of which
192+ // this guard lets cancel a running export.
192 let k = keymap::Keymap::defaults();193 let k = keymap::Keymap::defaults();
193 assert!(cancels_export("escape", true, k.lookup("escape", true)));194 assert!(cancels_export("escape", true, k.lookup("escape", true)));
194 assert!(!cancels_export("escape", false, k.lookup("escape", false)));195 assert!(!cancels_export("escape", false, k.lookup("escape", false)));
crates/app/src/tests/editing.rsmodified+60 -0
@@ -2179,3 +2179,63 @@ fn should_loop_restart_is_play_state_blind_the_pump_gates_it() {
2179 into-it -- that distinction is pump's is_playing() guard, not this"2179 into-it -- that distinction is pump's is_playing() guard, not this"
2180 );2180 );
2181 }2181 }
2182+
2183+/// This binary has no `TestAppContext` to press a live escape through, so the
2184+/// guard reads the ordering `render.rs`'s key listener actually runs: every
2185+/// card/menu/list close returns before the fallthrough that dispatches
2186+/// `ActionId::Deselect` ever runs, so escape with one of them open closes it
2187+/// and never touches `self.selected` -- the picks made before the card opened
2188+/// are still there once it is gone.
2189+#[test]
2190+fn escape_closes_a_card_before_it_can_ever_reach_deselect() {
2191+ let render_rs = src_text("render.rs");
2192+ let dispatch = render_rs
2193+ .find("if let Some(action) = action {")
2194+ .expect("the keymap fallthrough that fires Deselect");
2195+ for (guard, label) in [
2196+ ("if this.keys_open {", "the keys overlay"),
2197+ ("if this.dock_filter_edit {", "the dock filter"),
2198+ (
2199+ "if this.param_card_key(key, event.keystroke.modifiers.shift, cx) {",
2200+ "a param card",
2201+ ),
2202+ (
2203+ "if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) {",
2204+ "player fullscreen",
2205+ ),
2206+ ("let clip_menu = this.context_menu.take().is_some();", "the clip/row menu or a list"),
2207+ (
2208+ "if key == ESCAPE && !ctrl && this.preview_session.is_some() {",
2209+ "an open preview",
2210+ ),
2211+ ] {
2212+ let at = render_rs
2213+ .find(guard)
2214+ .unwrap_or_else(|| panic!("{label}'s own escape guard moved or was renamed"));
2215+ assert!(
2216+ at < dispatch,
2217+ "{label}'s guard reads after the Deselect dispatch -- escape would \
2218+ clear the selection before this card ever got a look at the key"
2219+ );
2220+ }
2221+}
2222+
2223+/// The other half: with nothing on screen to claim the key, bare escape falls
2224+/// all the way through to `Player::act`, whose `ActionId::Deselect` arm is
2225+/// the one place `self.selected` is emptied by a bare stroke rather than by
2226+/// picking something else.
2227+#[test]
2228+fn escape_with_nothing_open_empties_the_selection() {
2229+ let actions_rs = src_text("player/actions.rs");
2230+ assert!(
2231+ actions_rs.contains("ActionId::Deselect => {")
2232+ && actions_rs.contains("self.selected = Selection::new();"),
2233+ "the Deselect arm no longer clears self.selected"
2234+ );
2235+ let k = keymap::Keymap::defaults();
2236+ assert_eq!(
2237+ k.lookup("escape", false),
2238+ Some(ActionId::Deselect),
2239+ "bare escape must still route to Deselect for that arm to ever run"
2240+ );
2241+}
crates/app/src/tests/layout.rsmodified+5 -0
@@ -2664,6 +2664,11 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() {
2664 ),2664 ),
2665 (ActionId::Crossfade, "fade parity owns crossfade controls"),2665 (ActionId::Crossfade, "fade parity owns crossfade controls"),
2666 (ActionId::Dissolve, "fade parity owns dissolve controls"),2666 (ActionId::Dissolve, "fade parity owns dissolve controls"),
2667+ (
2668+ ActionId::Deselect,
2669+ "clicking empty timeline space already clears the selection with the mouse; \
2670+ bare escape is a keyboard-only accelerator for that existing door, not a new one",
2671+ ),
2667 ];2672 ];
2668 let darkroom = [2673 let darkroom = [
2669 "ui/bench_stance.rs",2674 "ui/bench_stance.rs",