Escape closes overlays even when focus sits in dock/inspector/bench
Browse files at this commita2d755789b88c2bd937778bd61208b33cac29fe8Parent: d880cde- fix
- Escape closes overlays even when focus sits in dock/inspector/bench
3 changed files +58 -1
- crates/app/src/player/cards.rs +31 -0
- crates/app/src/ui/dock_stance.rs +12 -0
- crates/app/src/ui/stance.rs +15 -1
crates/app/src/player/cards.rsmodified+31 -0
| @@ -1332,6 +1332,37 @@ impl Player { | ||
| 1332 | 1332 | self.subtitle_style_open = false; |
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 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 | + | |
| 1335 | 1366 | /// The one switch every param card's expand affordance and its `m` |
| 1336 | 1367 | /// chord both flip (`dark_card_head`, [`Player::param_card_key`]): |
| 1337 | 1368 | /// 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( | ||
| 1401 | 1401 | this.focus_surface(next, window, cx); |
| 1402 | 1402 | cx.stop_propagation(); |
| 1403 | 1403 | } 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 | + } | |
| 1404 | 1416 | // Same exit as `stance.rs`'s bench handler: leaves the ring for |
| 1405 | 1417 | // the root handle rather than letting escape bubble to whatever |
| 1406 | 1418 | // the root does with it. |
crates/app/src/ui/stance.rsmodified+15 -1
| @@ -683,6 +683,16 @@ fn bench( | ||
| 683 | 683 | this.focus_surface(next, window, cx); |
| 684 | 684 | cx.stop_propagation(); |
| 685 | 685 | } 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 | + } | |
| 686 | 696 | // Leaves the ring rather than deleting it: the root handle |
| 687 | 697 | // gets focus back, and a second escape there is what does |
| 688 | 698 | // whatever escape means at the root (nothing, today) -- |
| @@ -1092,8 +1102,12 @@ pub(crate) fn render( | ||
| 1092 | 1102 | // Escape is every card's own way out (`Player::close_card`, |
| 1093 | 1103 | // the same list `overlaid`/`modal` read) -- blocking every |
| 1094 | 1104 | // 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. | |
| 1095 | 1108 | if key == ESCAPE { |
| 1096 | - this.close_card(); | |
| 1109 | + this.escape_closes_overlay(cx); | |
| 1110 | + return; | |
| 1097 | 1111 | } |
| 1098 | 1112 | // FAULT 2, general shape: `context_menu`/`library_menu`/ |
| 1099 | 1113 | // `picker` are three of the four reasons `overlaid()` refuses |