Repository navigation
Fix arrow keys not working in browser surfaces and IME candidate selection #1423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fall through when WebKit declines a Command equivalent.
Line 11225 returns
resultunconditionally. IfWKWebView.performKeyEquivalent(with:)returnsfalsefor a Cmd shortcut it does not own, the originalNSWindow.performKeyEquivalent(with:)never runs, so window/menu handlers lose their chance. That can bypass repo-specific handlers like browser-popup Cmd+W, and native fallbacks such as window cycling.💡 Suggested fix
if let webView = firstResponderWebView { let result = webView.performKeyEquivalent(with: event) `#if` DEBUG dlog(" → webview direct: \(result)") `#endif` - return result + if result || !event.modifierFlags + .intersection(.deviceIndependentFlagsMask) + .contains(.command) { + return result + } }Based on learnings:
BrowserPopupPanel.performKeyEquivalent is the primary handler to close popups.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a false positive —
CmuxWebView.performKeyEquivalentalready handles Command key routing internally:shouldRouteCommandEquivalentDirectlyToMainMenu→ triesNSApp.mainMenu.performKeyEquivalent(line 155)handleBrowserSurfaceKeyEquivalent(line 164)super.performKeyEquivalent(WKWebView, line 171)All menu items and app shortcuts are resolved inside the CmuxWebView override before it returns. If it still returns
false, it means no handler claimed the event — the same outcome the originalNSWindow.performKeyEquivalentwalk would produce, except the original walk also risks hitting the broken SwiftUI hosting view path (which is exactly the bug this PR fixes).The only Command key where
shouldRouteCommandEquivalentDirectlyToMainMenureturnsfalseis Cmd+` (keyCode 50), which is intentionally excluded (confirmed by existing testtestCmdBacktickDoesNotRouteDirectlyToMainMenuWhenWebViewIsFirstResponder). In that case,super.performKeyEquivalentreturnsfalse, and our code correctly propagates that — same as the old path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@coderabbit-userThanks for the added context. I’ll verify your claim against the repo and get back with a short confirmation or tweak if anything looks off.🏁 Script executed:
Length of output: 26926
@coderabbit-userAgreed — this was a false positive. I verified the routing:In NSWindow.cmux_performKeyEquivalent, we first give the app-level handler a chance: handleBrowserSurfaceKeyEquivalent (Sources/AppDelegate.swift:11208–11213). Only then do we call firstResponderWebView.performKeyEquivalent and return its result (Lines 11220–11226).
CmuxWebView.performKeyEquivalent itself handles Command routing:
Tests cover this: Cmd+N/W/R are consumed via the menu when WebView is first responder, while Return / Cmd+Return are not, and Cmd+` is explicitly excluded from direct-menu routing (cmuxTests/CmuxWebViewKeyEquivalentTests.swift:184–209, 220–246, 814–820).
Given this, allowing fall-through to the original NSWindow.performKeyEquivalent when the WebView returns false would just re-enter the SwiftUI hierarchy we’re intentionally bypassing for this bug, without adding any valid handler opportunity. Also, there’s no BrowserPopupPanel or “cmux.browser-popup” identifier in this repo, so that prior guideline doesn’t apply here.
I’m retracting the concern; no change needed.
✏️ Learnings added
🧠 Learnings used