From a2d755789b88c2bd937778bd61208b33cac29fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 13:31:15 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(app):=20Escape=20closes=20ov?= =?UTF-8?q?erlays=20even=20when=20focus=20sits=20in=20dock/inspector/bench?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FOCUS-SURFACE ESCAPE SWALLOW: a menu/card/preview opened by a click into the clip section (or any focus ring: dock, inspector, bench) never closed on Escape, because each ring's own escape branch stopped propagation and moved focus back to the room root before the root's own overlay-closing logic ever ran. Adds Player::escape_closes_overlay (player/cards.rs), the one shared door mirroring the root handler's own escape branches (card_open / context_menu / library_menu / picker, then preview_session). The root handler now calls it too, so there is exactly one place that knows what escape closes. Every focus-ring escape branch (dock_stance.rs's shared cycle_on_key_down -- wired to both focus_dock and focus_inspector -- and stance.rs's bench handler) calls it first; only when nothing closed does the branch fall through to its own ring-exit behavior. --- crates/app/src/player/cards.rs | 31 +++++++++++++++++++++++++++++++ crates/app/src/ui/dock_stance.rs | 12 ++++++++++++ crates/app/src/ui/stance.rs | 16 +++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) 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