fix(engine): close Settings, Help, Leaderboard, and theme store on Esc
Test / test (pull_request) Successful in 10m16s
Test / test (pull_request) Successful in 10m16s
Phase C dismissal audit: Esc / scrim-tap / Done must behave the same on every modal. Stragglers found and fixed — none of these had any Esc path (pause's toggle guard swallowed the key while they were open): - Settings: Esc clears SettingsScreen, gated on being the topmost modal so a stacked sync-setup / theme-store dialog owns Esc - Help: Esc closes alongside F1/Done (the code comment already claimed an Esc path existed — now it does) - Leaderboard: Esc closes when topmost; the display-name dialog stacked above it now Esc-cancels like sync-setup's dialog - Theme store: Esc closes (always topmost when open) Scrim-tap opt-ins are unchanged — ui_modal documents which modals deliberately stay non-dismissible on outside clicks. Tests: escape_closes_help_screen, escape_closes_settings_screen_flag. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -86,13 +86,18 @@ fn toggle_help_screen(
|
||||
}
|
||||
|
||||
/// Click handler for the modal's "Done" button. F1 toggles the overlay
|
||||
/// the same way; this just exposes the close action to mouse / touch.
|
||||
/// the same way; Esc closes too, so dismissal matches every other
|
||||
/// modal (Phase C dismissal audit). Nothing ever stacks above Help,
|
||||
/// so Esc needs no topmost gate.
|
||||
fn handle_help_close_button(
|
||||
mut commands: Commands,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
close_buttons: Query<&Interaction, (With<HelpCloseButton>, Changed<Interaction>)>,
|
||||
screens: Query<Entity, With<HelpScreen>>,
|
||||
) {
|
||||
if !close_buttons.iter().any(|i| *i == Interaction::Pressed) {
|
||||
let clicked = close_buttons.iter().any(|i| *i == Interaction::Pressed);
|
||||
let esc = keys.just_pressed(KeyCode::Escape) && !screens.is_empty();
|
||||
if !clicked && !esc {
|
||||
return;
|
||||
}
|
||||
for entity in &screens {
|
||||
@@ -583,4 +588,33 @@ mod tests {
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/// Esc must dismiss the Help modal like Done and F1 do (Phase C
|
||||
/// dismissal audit).
|
||||
#[test]
|
||||
fn escape_closes_help_screen() {
|
||||
let mut app = headless_app();
|
||||
app.world_mut()
|
||||
.resource_mut::<ButtonInput<KeyCode>>()
|
||||
.press(KeyCode::F1);
|
||||
app.update();
|
||||
|
||||
{
|
||||
let mut input = app.world_mut().resource_mut::<ButtonInput<KeyCode>>();
|
||||
input.release(KeyCode::F1);
|
||||
input.clear();
|
||||
input.press(KeyCode::Escape);
|
||||
}
|
||||
app.update();
|
||||
app.update();
|
||||
|
||||
assert_eq!(
|
||||
app.world_mut()
|
||||
.query::<&HelpScreen>()
|
||||
.iter(app.world())
|
||||
.count(),
|
||||
0,
|
||||
"Esc must close the Help modal"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user