Skip to content

fix: Escape handling after fullscreen exit#3892

Open
baculinivan-web wants to merge 1 commit intoopenfrontio:mainfrom
baculinivan-web:esc-build-fullscreen-fix
Open

fix: Escape handling after fullscreen exit#3892
baculinivan-web wants to merge 1 commit intoopenfrontio:mainfrom
baculinivan-web:esc-build-fullscreen-fix

Conversation

@baculinivan-web
Copy link
Copy Markdown
Contributor

@baculinivan-web baculinivan-web commented May 9, 2026

Description:

This PR fixes Escape handling when the browser exits fullscreen mode.

Before this change, pressing Esc in fullscreen mode could be consumed by the browser fullscreen exit before the game handled it. As a result, in-game views and menus that normally close on Esc stayed open until pressing Esc a second time after fullscreen had already exited.

This also affected structure placement: the active ghost building could remain stuck after fullscreen exit because the build state was not cleared at the same time.

The input handler now listens for fullscreenchange and emits the same close-view flow used by regular Esc handling when fullscreen exits. If a ghost structure is active, it is cleared as well so placement state does not remain stuck.

Added regression coverage for:

  • Esc cancelling an active build ghost without blocking other keydown handlers
  • fullscreen exit closing active views
  • fullscreen exit clearing active ghost build state

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

fghjk_60845

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Review Change Stack

Walkthrough

InputHandler tracks fullscreen via a new wasFullscreen flag, adds a capturing Escape key handler to cancel active ghost builds, cancels ghosts on fullscreen exit, unregisters those listeners in destroy(), and tests assert cancellation, event emission, default prevention, and listener ordering including fullscreen-exit-before-Escape.

Changes

Ghost Structure Cancellation with Escape and Fullscreen Exit

Layer / File(s) Summary
State Tracking
src/client/InputHandler.ts
New wasFullscreen private flag declared and initialized from document.fullscreenElement during initialize() to track fullscreen mode state.
Event Listener Registration & Cleanup
src/client/InputHandler.ts
Capturing keydown and fullscreenchange listeners are registered during initialize() and removed in destroy().
Ghost Cancellation Handlers
src/client/InputHandler.ts
Private methods added: handleEscapeCapture() cancels ghost on Escape when target is not a text input and prevents default, handleFullscreenChange() clears ghosts on fullscreen exit, and cancelGhostStructure() centralizes ghost nullification and event emission.
Tests and Verification
tests/InputHandler.test.ts
Import GhostStructureChangedEvent and add tests verifying Escape clears uiState.ghostStructure, sets defaultPrevented, emits GhostStructureChangedEvent, preserves other keydown listeners, and that exiting fullscreen clears the ghost even before Escape.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

In fullscreen's fade and Escape's soft sigh,
The ghost retreats, no default flies,
Events are sent, listeners stay kind,
State reset clean, no trace behind. 👻✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title directly describes the main fix: handling Escape key input correctly after fullscreen exit, which is the core problem addressed in this PR.
Description check ✅ Passed The pull request description clearly explains the problem (Escape handling in fullscreen mode), the solution (listening for fullscreenchange and clearing ghost structures), and what tests were added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@baculinivan-web baculinivan-web force-pushed the esc-build-fullscreen-fix branch from da6d2d5 to a0a351f Compare May 9, 2026 16:28
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/client/InputHandler.ts`:
- Around line 856-868: In handleEscapeCapture (the capture-phase Escape key
handler) remove the call to event.stopImmediatePropagation() so it no longer
blocks other keydown listeners (like those that emit CloseViewEvent); keep
cancelGhostStructure() and event.preventDefault() but drop the
stopImmediatePropagation call and avoid redundantly setting ghost state here
since the regular handler calls setGhostStructure(null); use the existing
symbols handleEscapeCapture, cancelGhostStructure, isTextInputTarget, and
uiState.ghostStructure to locate and edit the handler.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66278d45-10dc-4933-82f1-7a6aec812549

📥 Commits

Reviewing files that changed from the base of the PR and between 2b04c56 and da6d2d5.

📒 Files selected for processing (2)
  • src/client/InputHandler.ts
  • tests/InputHandler.test.ts

Comment thread src/client/InputHandler.ts
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management May 9, 2026
@baculinivan-web baculinivan-web force-pushed the esc-build-fullscreen-fix branch from a0a351f to 75570b5 Compare May 9, 2026 16:33
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 9, 2026
@baculinivan-web baculinivan-web changed the title fix: Fix build cancel in fullscreen fix: Escape handling after fullscreen exit May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

1 participant