From 842cc98cbed1c6315df33423babfe6448f6a792f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 19:45:13 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(keymap):=20escape=20clears=20t?= =?UTF-8?q?he=20selection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/app/src/keymap.rs | 16 +++++++-- crates/app/src/player/actions.rs | 6 ++++ crates/app/src/tests/cards.rs | 5 +-- crates/app/src/tests/editing.rs | 60 ++++++++++++++++++++++++++++++++ crates/app/src/tests/layout.rs | 5 +++ 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 91c1cc4..8cd69ec 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -118,6 +118,9 @@ actions! { /// ctrl-click that builds a selection by hand, for the times everything /// wants selecting at once. SelectAll, + /// Bare escape with nothing else claiming it: empties a multi-clip + /// selection without touching picks, cards or fullscreen. + Deselect, Delete, Lift, Color, @@ -256,6 +259,7 @@ impl ActionId { ActionId::SelectNext => "Select the next clip in the lane", ActionId::SelectPrev => "Select the previous clip in the lane", ActionId::SelectAll => "Select everything (every clip and caption)", + ActionId::Deselect => "Clear the selection", ActionId::Delete => "Delete", ActionId::Lift => "Lift (leave a gap)", ActionId::Color => "Colour…", @@ -335,6 +339,7 @@ impl ActionId { ActionId::SelectNext => "select-next", ActionId::SelectPrev => "select-prev", ActionId::SelectAll => "select-all", + ActionId::Deselect => "deselect", ActionId::Delete => "delete", ActionId::Lift => "lift", ActionId::Color => "color", @@ -413,6 +418,7 @@ impl ActionId { | ActionId::SelectNext | ActionId::SelectPrev | ActionId::SelectAll + | ActionId::Deselect | ActionId::Delete | ActionId::Lift | ActionId::Color @@ -1055,6 +1061,10 @@ impl Keymap { // below had to move off ctrl+a: a stroke that universal was // never really the removal's to keep. b(ActionId::SelectAll, "a", true), + // Bare escape, last in the precedence chain behind every card, + // search and fullscreen close (render.rs) -- just empties the + // selection when nothing else claims the key. + b(ActionId::Deselect, "escape", false), b(ActionId::Delete, "x", false), b(ActionId::Delete, "delete", false), b(ActionId::Lift, "l", false), @@ -1500,7 +1510,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 74); + assert_eq!(k.entries().len(), 75); // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. // actually type) strides ten. assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); @@ -1584,9 +1594,9 @@ mod tests { assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp)); assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown)); assert_eq!(k.lookup("+", false), None); - // The chord, and *only* the chord: bare escape reaches no action at all. + // The chord cancels an export; bare escape falls through to Deselect. assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport)); - assert_eq!(k.lookup("escape", false), None); + assert_eq!(k.lookup("escape", false), Some(ActionId::Deselect)); // The modifier is half the chord: ctrl+e is not e. assert_eq!(k.lookup("e", true), None); assert_eq!(k.lookup("space", true), None); diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index cc02bb9..3fff4df 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -98,6 +98,12 @@ impl Player { ActionId::SelectNext => self.select_step(true, cx), ActionId::SelectPrev => self.select_step(false, cx), ActionId::SelectAll => self.select_all(cx), + // Last in escape's precedence chain (render.rs): nothing else + // claimed the key, so it just empties the selection. + ActionId::Deselect => { + self.selected = Selection::new(); + cx.notify(); + } ActionId::Delete => self.delete_selected(cx), ActionId::Lift => self.lift_selected(cx), ActionId::Color => self.open_color(cx), diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 55a6017..3a8c23f 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -186,8 +186,9 @@ fn only_a_chord_gets_out_of_an_export() { assert!(!cancels_export("e", false, Some(ActionId::Export))); assert!(!cancels_export("space", false, Some(ActionId::Play))); assert!(!cancels_export("q", false, None)); - // The default keymap is what the handler feeds this: the chord reaches the - // action, the bare key reaches nothing. + // The default keymap is what the handler feeds this: the chord reaches + // CancelExport, the bare key reaches Deselect instead -- neither of which + // this guard lets cancel a running export. let k = keymap::Keymap::defaults(); assert!(cancels_export("escape", true, k.lookup("escape", true))); assert!(!cancels_export("escape", false, k.lookup("escape", false))); diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index b8a8763..793b78a 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -2179,3 +2179,63 @@ fn should_loop_restart_is_play_state_blind_the_pump_gates_it() { into-it -- that distinction is pump's is_playing() guard, not this" ); } + +/// This binary has no `TestAppContext` to press a live escape through, so the +/// guard reads the ordering `render.rs`'s key listener actually runs: every +/// card/menu/list close returns before the fallthrough that dispatches +/// `ActionId::Deselect` ever runs, so escape with one of them open closes it +/// and never touches `self.selected` -- the picks made before the card opened +/// are still there once it is gone. +#[test] +fn escape_closes_a_card_before_it_can_ever_reach_deselect() { + let render_rs = src_text("render.rs"); + let dispatch = render_rs + .find("if let Some(action) = action {") + .expect("the keymap fallthrough that fires Deselect"); + for (guard, label) in [ + ("if this.keys_open {", "the keys overlay"), + ("if this.dock_filter_edit {", "the dock filter"), + ( + "if this.param_card_key(key, event.keystroke.modifiers.shift, cx) {", + "a param card", + ), + ( + "if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) {", + "player fullscreen", + ), + ("let clip_menu = this.context_menu.take().is_some();", "the clip/row menu or a list"), + ( + "if key == ESCAPE && !ctrl && this.preview_session.is_some() {", + "an open preview", + ), + ] { + let at = render_rs + .find(guard) + .unwrap_or_else(|| panic!("{label}'s own escape guard moved or was renamed")); + assert!( + at < dispatch, + "{label}'s guard reads after the Deselect dispatch -- escape would \ + clear the selection before this card ever got a look at the key" + ); + } +} + +/// The other half: with nothing on screen to claim the key, bare escape falls +/// all the way through to `Player::act`, whose `ActionId::Deselect` arm is +/// the one place `self.selected` is emptied by a bare stroke rather than by +/// picking something else. +#[test] +fn escape_with_nothing_open_empties_the_selection() { + let actions_rs = src_text("player/actions.rs"); + assert!( + actions_rs.contains("ActionId::Deselect => {") + && actions_rs.contains("self.selected = Selection::new();"), + "the Deselect arm no longer clears self.selected" + ); + let k = keymap::Keymap::defaults(); + assert_eq!( + k.lookup("escape", false), + Some(ActionId::Deselect), + "bare escape must still route to Deselect for that arm to ever run" + ); +} diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 9e9ad3f..a975810 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2633,6 +2633,11 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { ), (ActionId::Crossfade, "fade parity owns crossfade controls"), (ActionId::Dissolve, "fade parity owns dissolve controls"), + ( + ActionId::Deselect, + "clicking empty timeline space already clears the selection with the mouse; \ + bare escape is a keyboard-only accelerator for that existing door, not a new one", + ), ]; let darkroom = [ "ui/bench_stance.rs",