Skip to content

ESC key functionality to close settings modal - #6

Merged
Rhylanscript merged 2 commits into
mainfrom
fix/settings-modal-esc
Sep 21, 2026
Merged

Rhylanscript merged 2 commits into
mainfrom
fix/settings-modal-esc

Conversation

@Rhylanscript

Copy link
Copy Markdown
Collaborator

Added

  • Esc - now closes GeoHelper settings modal

Fixed

  • While GeoHelper settings modal is open, Esc doesn't close OpenGuessr menu anymore

@Rhylanscript Rhylanscript added the bug Something isn't working label Sep 21, 2026
@Rhylanscript Rhylanscript linked an issue Sep 21, 2026 that may be closed by this pull request

@Eli-Zac Eli-Zac left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, focused change — single delegated listener registered once inside the IIFE (no leak, no per-open wiring), guard is cheap, and the version bump to 1.0.3 matches the release-tagging convention. CI is green.

Two things before merge:

  1. Esc during the close animation (inline on content.js:872) — the overlay lingers in the DOM for up to 300ms while .gg-settings-leave plays, so a second Esc in that window re-enters closeSettingsModal() and, more noticeably, is still swallowed, so the OpenGuessr menu won't react. Suggested a one-line guard.
  2. Capture-phase assumption (inline on content.js:874) — document capture only beats the site's handler if the site doesn't bind on window. Worth confirming the "Esc no longer closes the OpenGuessr menu while the modal is open" part actually holds in game; stopImmediatePropagation() would also cover a same-node listener.

Neither is blocking in the sense of being broken today — (1) is a small real gap, (2) is just a claim in the PR description I can't verify from the diff. Happy to approve once (1) is in and you've confirmed (2).

Comment thread content.js Outdated
document.addEventListener(
"keydown",
(e) => {
if (e.key !== "Escape" || !document.getElementById(SETTINGS_MODAL_ID)) return;

@Eli-Zac Eli-Zac Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closeSettingsModal() doesn't remove the overlay immediately — it adds .gg-settings-leave and removes on transitionend, with a 300ms fallback. So for up to 300ms after the first Esc, getElementById(SETTINGS_MODAL_ID) is still truthy and this guard passes again:

  • a second Esc during the close animation re-enters closeSettingsModal(), re-adding the leave class plus another transitionend listener and another setTimeout (harmless, but redundant), and
  • more visibly, that Esc is still preventDefault()/stopPropagation()-ed, so the OpenGuessr menu won't respond to it. Holding Esc (key auto-repeat) lands in the same window.

Gating on the closing state fixes both:

Suggested change
if (e.key !== "Escape" || !document.getElementById(SETTINGS_MODAL_ID)) return;
if (e.key !== "Escape") return;
const overlay = document.getElementById(SETTINGS_MODAL_ID);
if (!overlay || overlay.querySelector(".gg-settings-leave")) return;

Comment thread content.js Outdated
(e) => {
if (e.key !== "Escape" || !document.getElementById(SETTINGS_MODAL_ID)) return;
e.preventDefault();
e.stopPropagation();

@Eli-Zac Eli-Zac Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things on the propagation stop, both worth a quick in-game sanity check rather than a code change up front:

  1. stopPropagation() in the capture phase on document blocks listeners further down the tree, but capture runs window → document → … , so if OpenGuessr binds its Esc handler on window (capture), its handler already ran before this one and the "Esc no longer closes the OpenGuessr menu" fix won't hold. Worth confirming the modal-open case actually behaves in the game.
  2. If the site happens to bind on document too, stopPropagation() won't stop it — sibling listeners on the same node still fire. stopImmediatePropagation() would cover that case as well.

@Rhylanscript

Copy link
Copy Markdown
Collaborator Author

thanks for the feedback human lemme fix these rq

@Rhylanscript

Copy link
Copy Markdown
Collaborator Author

Changes have been Addressed, I have confirmed through testing that pressing ESC on settings modal only closes toplevel modal and not the menu, updated to e.stopImmediatePropagation() anyway though.

@Eli-Zac Eli-Zac left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both points addressed and confirmed in game. CI green. Looks good to me.

@Rhylanscript
Rhylanscript merged commit c833439 into main Sep 21, 2026
1 check passed
@Rhylanscript
Rhylanscript deleted the fix/settings-modal-esc branch September 21, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeoHelper Settings Modal Closing on ESC

2 participants