Repository navigation
ESC key functionality to close settings modal - #6
Conversation
There was a problem hiding this comment.
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:
- Esc during the close animation (inline on
content.js:872) — the overlay lingers in the DOM for up to 300ms while.gg-settings-leaveplays, so a second Esc in that window re-enterscloseSettingsModal()and, more noticeably, is still swallowed, so the OpenGuessr menu won't react. Suggested a one-line guard. - Capture-phase assumption (inline on
content.js:874) —documentcapture only beats the site's handler if the site doesn't bind onwindow. 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).
| document.addEventListener( | ||
| "keydown", | ||
| (e) => { | ||
| if (e.key !== "Escape" || !document.getElementById(SETTINGS_MODAL_ID)) return; |
There was a problem hiding this comment.
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 anothertransitionendlistener and anothersetTimeout(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:
| 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; |
| (e) => { | ||
| if (e.key !== "Escape" || !document.getElementById(SETTINGS_MODAL_ID)) return; | ||
| e.preventDefault(); | ||
| e.stopPropagation(); |
There was a problem hiding this comment.
Two things on the propagation stop, both worth a quick in-game sanity check rather than a code change up front:
stopPropagation()in the capture phase ondocumentblocks listeners further down the tree, but capture runswindow→document→ … , so if OpenGuessr binds its Esc handler onwindow(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.- If the site happens to bind on
documenttoo,stopPropagation()won't stop it — sibling listeners on the same node still fire.stopImmediatePropagation()would cover that case as well.
|
thanks for the feedback human lemme fix these rq |
|
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 |
Eli-Zac
left a comment
There was a problem hiding this comment.
Both points addressed and confirmed in game. CI green. Looks good to me.
Added
Esc- now closes GeoHelper settings modalFixed
Escdoesn't close OpenGuessr menu anymore