forge
Explore
Log in

Don't you dare go Hollow

Escape closes overlays even when focus sits in dock/inspector/bench

Browse files at this commit

a2d755789b88c2bd937778bd61208b33cac29fe8Ahmet Kaan GümüşParent: d880cde
  • fix
    • Escape closes overlays even when focus sits in dock/inspector/bench
Show full message
🐛 fix(app): Escape closes overlays even when focus sits in dock/inspector/bench

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.rsmodified+31 -0
@@ -1332,6 +1332,37 @@ impl Player {
13321332 self.subtitle_style_open = false;
13331333 }
13341334
1335+ /// Escape's one door to every dismissible overlay the room can have up
1336+ /// (`ui::stance::render`'s root `on_key_down`'s own escape branches,
1337+ /// mirrored here exactly): a focus surface with its own escape branch
1338+ /// (dock/inspector's `cycle_on_key_down`, the bench's handler) calls
1339+ /// this FIRST, before its own ring-exit behavior, so an overlay opened
1340+ /// by a click into that surface still closes on the first escape
1341+ /// instead of the ring's `stop_propagation` swallowing the key before
1342+ /// the root ever sees it (the "esc does not close menus opened by
1343+ /// clicking in the clip section" report). Returns whether it closed
1344+ /// something, so a caller only falls through to its own ring-exit
1345+ /// behavior when nothing was open to close.
1346+ pub(crate) fn escape_closes_overlay(&mut self, cx: &mut Context<Self>) -> bool {
1347+ if self.card_open()
1348+ || self.context_menu.is_some()
1349+ || self.library_menu.is_some()
1350+ || self.picker.is_some()
1351+ {
1352+ self.close_card();
1353+ self.context_menu = None;
1354+ self.library_menu = None;
1355+ self.picker = None;
1356+ cx.notify();
1357+ return true;
1358+ }
1359+ if self.preview_session.is_some() {
1360+ self.close_preview(cx);
1361+ return true;
1362+ }
1363+ false
1364+ }
1365+
13351366 /// The one switch every param card's expand affordance and its `m`
13361367 /// chord both flip (`dark_card_head`, [`Player::param_card_key`]):
13371368 /// whichever card is open trades its usual capped, floating size for the
crates/app/src/ui/dock_stance.rsmodified+12 -0
@@ -1401,6 +1401,18 @@ fn cycle_on_key_down(
14011401 this.focus_surface(next, window, cx);
14021402 cx.stop_propagation();
14031403 } else if is_focus_exit_key(key) {
1404+ // A dismissible overlay (context menu, library menu, picker, any
1405+ // card, a live preview) opened by a click into the dock/inspector
1406+ // takes this escape first -- the same door the root handler
1407+ // itself closes it through (`Player::escape_closes_overlay`) --
1408+ // so it does not go on sitting open just because focus happened
1409+ // to be inside this ring when escape was pressed (the "esc is
1410+ // not closing menus opened by clicking in the clip section"
1411+ // report).
1412+ if this.escape_closes_overlay(cx) {
1413+ cx.stop_propagation();
1414+ return;
1415+ }
14041416 // Same exit as `stance.rs`'s bench handler: leaves the ring for
14051417 // the root handle rather than letting escape bubble to whatever
14061418 // the root does with it.
crates/app/src/ui/stance.rsmodified+15 -1
@@ -683,6 +683,16 @@ fn bench(
683683 this.focus_surface(next, window, cx);
684684 cx.stop_propagation();
685685 } else if is_focus_exit_key(key) {
686+ // A dismissible overlay (context menu, library menu, picker,
687+ // any card, a live preview) opened by a click into the bench
688+ // takes this escape first -- the same door the root handler
689+ // itself closes it through (`Player::escape_closes_overlay`)
690+ // -- so it does not go on sitting open just because focus
691+ // happened to be inside this ring when escape was pressed.
692+ if this.escape_closes_overlay(cx) {
693+ cx.stop_propagation();
694+ return;
695+ }
686696 // Leaves the ring rather than deleting it: the root handle
687697 // gets focus back, and a second escape there is what does
688698 // whatever escape means at the root (nothing, today) --
@@ -1092,8 +1102,12 @@ pub(crate) fn render(
10921102 // Escape is every card's own way out (`Player::close_card`,
10931103 // the same list `overlaid`/`modal` read) -- blocking every
10941104 // key while a card is open must not also lock the card open.
1105+ // `escape_closes_overlay` (`player/cards.rs`) is the same
1106+ // call a focus surface's own escape branch makes first, so
1107+ // this and that never disagree on what escape closes.
10951108 if key == ESCAPE {
1096- this.close_card();
1109+ this.escape_closes_overlay(cx);
1110+ return;
10971111 }
10981112 // FAULT 2, general shape: `context_menu`/`library_menu`/
10991113 // `picker` are three of the four reasons `overlaid()` refuses