diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index dfdae2a..c48163a 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1332,6 +1332,37 @@ impl Player { self.subtitle_style_open = false; } + /// Escape's one door to every dismissible overlay the room can have up + /// (`ui::stance::render`'s root `on_key_down`'s own escape branches, + /// mirrored here exactly): a focus surface with its own escape branch + /// (dock/inspector's `cycle_on_key_down`, the bench's handler) calls + /// this FIRST, before its own ring-exit behavior, so an overlay opened + /// by a click into that surface still closes on the first escape + /// instead of the ring's `stop_propagation` swallowing the key before + /// the root ever sees it (the "esc does not close menus opened by + /// clicking in the clip section" report). Returns whether it closed + /// something, so a caller only falls through to its own ring-exit + /// behavior when nothing was open to close. + pub(crate) fn escape_closes_overlay(&mut self, cx: &mut Context) -> bool { + if self.card_open() + || self.context_menu.is_some() + || self.library_menu.is_some() + || self.picker.is_some() + { + self.close_card(); + self.context_menu = None; + self.library_menu = None; + self.picker = None; + cx.notify(); + return true; + } + if self.preview_session.is_some() { + self.close_preview(cx); + return true; + } + false + } + /// The one switch every param card's expand affordance and its `m` /// chord both flip (`dark_card_head`, [`Player::param_card_key`]): /// whichever card is open trades its usual capped, floating size for the diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 881c9c9..a16e053 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1401,6 +1401,18 @@ fn cycle_on_key_down( this.focus_surface(next, window, cx); cx.stop_propagation(); } else if is_focus_exit_key(key) { + // A dismissible overlay (context menu, library menu, picker, any + // card, a live preview) opened by a click into the dock/inspector + // takes this escape first -- the same door the root handler + // itself closes it through (`Player::escape_closes_overlay`) -- + // so it does not go on sitting open just because focus happened + // to be inside this ring when escape was pressed (the "esc is + // not closing menus opened by clicking in the clip section" + // report). + if this.escape_closes_overlay(cx) { + cx.stop_propagation(); + return; + } // Same exit as `stance.rs`'s bench handler: leaves the ring for // the root handle rather than letting escape bubble to whatever // the root does with it. diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index def8f44..88430f7 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -683,6 +683,16 @@ fn bench( this.focus_surface(next, window, cx); cx.stop_propagation(); } else if is_focus_exit_key(key) { + // A dismissible overlay (context menu, library menu, picker, + // any card, a live preview) opened by a click into the bench + // takes this escape first -- the same door the root handler + // itself closes it through (`Player::escape_closes_overlay`) + // -- so it does not go on sitting open just because focus + // happened to be inside this ring when escape was pressed. + if this.escape_closes_overlay(cx) { + cx.stop_propagation(); + return; + } // Leaves the ring rather than deleting it: the root handle // gets focus back, and a second escape there is what does // whatever escape means at the root (nothing, today) -- @@ -1092,8 +1102,12 @@ pub(crate) fn render( // Escape is every card's own way out (`Player::close_card`, // the same list `overlaid`/`modal` read) -- blocking every // key while a card is open must not also lock the card open. + // `escape_closes_overlay` (`player/cards.rs`) is the same + // call a focus surface's own escape branch makes first, so + // this and that never disagree on what escape closes. if key == ESCAPE { - this.close_card(); + this.escape_closes_overlay(cx); + return; } // FAULT 2, general shape: `context_menu`/`library_menu`/ // `picker` are three of the four reasons `overlaid()` refuses