Skip to content

fix(application): let registered accelerators win over the webview on… - #5902

Open
julianstorer wants to merge 2 commits into
wailsapp:masterfrom
juggler-ai:fix/mac-accelerator-key-equivalent
Open

fix(application): let registered accelerators win over the webview on…#5902
julianstorer wants to merge 2 commits into
wailsapp:masterfrom
juggler-ai:fix/mac-accelerator-key-equivalent

Conversation

@julianstorer

@julianstorer julianstorer commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

On macOS the WKWebView is first responder and swallows most key events before
they reach NSWindow's keyDown:. Common combos like Ctrl+Tab never get there,
so an app-registered KeyBinding for them silently never fires.

This overrides performKeyEquivalent: on WebviewWindow, which runs before the
responder chain and before NSMenu's own key-equivalent dispatch. It calls into
Go with the same accelerator string keyDown: builds, looks it up via the
existing processKeyBinding path, and returns YES only on a real match. On a
miss it falls through to super, so main-menu key equivalents and every other
Cocoa default keep working — only accelerators the app explicitly registered are
claimed. The modifier-string assembly is factored out of keyDown: into
acceleratorStringFromEvent: so both callers produce identical strings.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Registered a KeyBinding for an accelerator the webview otherwise consumes (e.g.
Ctrl+Tab) and confirmed the binding now fires, while unregistered combos and
main-menu shortcuts behave unchanged.

  • Windows
  • macOS
  • Linux

Summary by CodeRabbit

  • Bug Fixes
    • Improved macOS keyboard shortcut handling for webview windows.
    • Shortcuts are now processed consistently and correctly report whether they were handled.
    • Unrecognized or unavailable shortcuts continue through the system’s standard handling.

… macOS

On macOS the WKWebView is first responder and swallows most key events
before they reach NSWindow's keyDown:. Common combos like Ctrl+Tab never get
there, so an app-registered KeyBinding for them silently never fires.

Override performKeyEquivalent: on WebviewWindow, which runs before the
responder chain and before NSMenu's own key-equivalent dispatch. It calls
into Go with the same accelerator string keyDown: builds, looks it up via
the existing processKeyBinding path, and returns YES only on a real match.
On a miss it falls through to super, so main-menu key equivalents and every
other Cocoa default keep working — only accelerators the app explicitly
registered are claimed.

The Go side is a synchronous sibling of processWindowKeyDownEvent rather
than a channel send, because performKeyEquivalent: needs the answer
immediately to decide whether to consume the event. It's a single map read
under RLock plus the same goroutine dispatch processKeyBinding already does,
so the threading matches the keyDown: path. The modifier-string assembly is
pulled out of keyDown: into acceleratorStringFromEvent: so both callers
produce identical strings.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 30ec88d7-a5df-4bf1-bda4-3a03d934061d

📥 Commits

Reviewing files that changed from the base of the PR and between 5ececdf and 3414777.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_darwin.m
🚧 Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/webview_window_darwin.m

Walkthrough

macOS keyboard equivalents now build accelerator strings and call a synchronous Go callback. The callback validates the window and accelerator, invokes processKeyBinding, and returns whether Cocoa should continue handling the event.

Changes

macOS key-equivalent processing

Layer / File(s) Summary
Go key binding callback
v3/pkg/application/application_darwin.go
The exported processWindowKeyEquivalent callback validates the window and accelerator, then returns the result from processKeyBinding.
Darwin event bridge
v3/pkg/application/webview_window_darwin.m
The Objective-C code extracts accelerator construction into acceleratorStringFromEvent: and calls the Go callback from performKeyEquivalent: before Cocoa fallback handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit taps keys in the morning light,
Builds one accelerator, clean and tight.
Go checks the window, bindings reply,
Cocoa steps back when the shortcut flies.
Hop, hop—handled, the event is done!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title refers to a specific part of the changeset (accelerators on macOS webview) but is incomplete and cut off, making it unclear. Complete the title to clearly state the main change; for example: 'fix(application): let registered accelerators win over webview on macOS'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the problem, solution, testing approach, and includes checked type and platform checkboxes as required.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant