fix(v2): Prevent Esc from exiting fullscreen on macOS#5242
Conversation
Override cancelOperation: in WailsWindow to check if the window is in fullscreen mode. When fullscreen, the Esc key press is swallowed so web content can handle it (e.g., closing modals). When not fullscreen, the default behavior is preserved. Note: This is a macOS-only fix. Needs manual testing on macOS to verify.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
🤖 PR Triage Review ✅ Accepted This PR prevents Esc key from exiting fullscreen on macOS (v2). Important UX fix to match platform conventions. Platform: macOS (v2-only) Next Steps: Dispatching for Mac testing. Reviewed by Wails PR Reviewer Bot |
…Fullscreen Adds an opt-in mac.Options.DisableEscapeExitsFullscreen field. When true, WailsWindow.cancelOperation: swallows the Esc keypress in fullscreen so web content (modals, custom handlers) can consume it. When false (default), the standard macOS behaviour is preserved — Esc exits fullscreen. Threads the bool through Create()/CreateWindow() so the property is set on the WailsWindow at creation. Existing apps see no behaviour change. Closes #4649
|
This PR has been superseded by #5310, which refactors the |
…Esc (#5307) Add DisableEscapeExitsFullscreen bool to MacWindow options so apps can opt in to preventing the Escape key from exiting fullscreen mode, allowing web content (e.g. modals with Esc-to-close behaviour) to handle Esc without triggering the macOS system behaviour that exits the fullscreen window. The flag is stored as a BOOL property on WebviewWindow (the custom NSWindow subclass) and checked in a cancelOperation: override: when the window is fullscreen and the flag is true, the Esc keypress is swallowed; otherwise the default macOS behaviour is preserved via [super cancelOperation:sender]. Default false, so all existing apps are unaffected. Ports v2 PR #5242 to v3. Co-authored-by: wails-fleet-bot <noreply@wails-fleet.local>
Summary
Fixes #4649
On macOS, pressing the Escape key while a Wails app is in fullscreen mode would exit fullscreen, preventing web content (e.g., modals, dialogs) from handling the Esc key.
Fix
Override
cancelOperation:inWailsWindow(NSWindow subclass) to check if the window is currently in fullscreen mode:cancelOperation:message is swallowed, allowing the Esc keypress to reach the web content via WKWebView's normal key event handling.cancelOperation:behavior is preserved.This is the standard macOS pattern for customizing Esc behavior in fullscreen apps.
Files Changed
v2/internal/frontend/desktop/darwin/WailsContext.m- AddedcancelOperation:override toWailsWindowv2/test/4649/test_esc_fullscreen.go- Manual test documentationTest Plan
This is a macOS-only fix and needs manual testing on macOS:
💡 This PR was created by the Wails Engineer agent.