Repository navigation
Fix remapped Cmd+W close shortcuts - #4406
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughCentralizes configured-shortcut dispatch and checks configured shortcuts before suppressing stale AppKit menu-backed shortcuts; refactors stale-suppression logic; updates application and window event overrides to consult the new routing; adds regression tests for close-related and numbered-digit shortcut reassignment. ChangesKeyboard Shortcut Priority Routing
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 16 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (16 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThis PR fixes the case where stale AppKit menu shortcuts for close actions (
Confidence Score: 5/5Safe to merge. The changes are tightly scoped to the stale-menu suppression and event-routing path, the new logic correctly identifies close-type stale actions and routes configured shortcuts before any menu fallback, and the regression tests confirm correct behavior for all three close defaults and the Cmd+W reassignment scenario. The refactored shouldSuppressStaleCmuxMenuShortcut preserves all pre-existing non-close semantics exactly (numbered-digit matching, the all-actions current-shortcut guard), and the new close-action early-return is the minimal targeted fix for the described split-owner race. The handleConfiguredShortcutKeyEquivalent extraction is a transparent delegation with no behavior change for existing callers. No actor isolation issues, no blocking primitives, no user-facing text, and no production logging changes. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[NSApp.sendEvent / NSWindow.performKeyEquivalent\nreceives keyDown event] --> B{shouldSuppressStaleCmuxMenuShortcut?}
B -->|No| C[Normal AppKit dispatch\nMenu item fires normally]
B -->|Yes| D{handleConfiguredShortcutKeyEquivalent\nhandleCustomShortcut}
D -->|true - action fired| E[Return: event consumed\nConfigured shortcut ran]
D -->|false - nothing matched| F[Forward to Ghostty view\nor suppress stale menu]
subgraph shouldSuppressStaleCmuxMenuShortcut
G[Build staleDefaultActions:\nmenu-backed actions whose\ndefault shortcut matches event] --> H{staleDefaultActions\nempty?}
H -->|Yes| I[return false]
H -->|No| J{Any stale action still\nowns the key via\ncurrent shortcut?}
J -->|Yes| K[return false\nnot actually stale]
J -->|No| L{staleDefaultActions\ncontains a close action?}
L -->|Yes - CLOSE PATH| M[return true\nalways suppress stale close default]
L -->|No - NON-CLOSE PATH| N{Any action currently\nowns this key?}
N -->|Yes| O[return false\nconfigured shortcut handles it via local monitor]
N -->|No| P[return true\nsuppress orphaned stale default]
end
Reviews (3): Last reviewed commit: "test: keep cmd-w send-event regression i..." | Re-trigger Greptile |
There was a problem hiding this comment.
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 `@Sources/AppDelegate.swift`:
- Around line 13554-13560: The fallback loop that currently only calls
matchesKeyboardShortcutEvent(event, action: action, shortcut: currentShortcut)
can miss actions that use numbered-digit matching; update the loop in the
consume-after-chord-mismatch path (iterating
KeyboardShortcutSettings.Action.allCases and using
KeyboardShortcutSettings.shortcut(for:)) to also check for numbered-digit
matches by calling the existing numberedShortcutDigit(event: currentShortcut)
(or equivalent helper) when the action's usesNumberedDigitMatching is true, and
treat that as a match (i.e., return false to avoid suppression) just as
matchesKeyboardShortcutEvent does before finally returning true.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e4876a78-d1bc-40b0-96b7-135b3a7a448b
📒 Files selected for processing (2)
Sources/AppDelegate.swiftcmuxTests/AppDelegateShortcutRoutingTests.swift
Dismissed stale CodeRabbit review: its only actionable inline thread was addressed in d198a96 and is resolved; CodeRabbit check is passing.
Fixes #1488
Summary
Reproduction / evidence
Test structure
Testing
CMUX_SKIP_ZIG_BUILD=1 ./scripts/reload.sh --tag issue-1488-cmd-w-remap-broken --launchbuilt successfully locally.reload.shfirst socket check timed out, then the built tagged app was opened directly;/tmp/cmux-debug-issue-1488-cmd-w-remap-broken.sockwas created and the app stayed running.Need help on this PR? Tag
@codesmithwith what you need.Note
Medium Risk
Changes event/shortcut routing for Command-key equivalents (including
Cmd+W) and stale-menu suppression logic, which can subtly impact global keyboard handling across windows. Added regression tests reduce risk but behavior changes may affect edge-case shortcuts and AppKit menu interactions.Overview
Fixes cases where remapped close shortcuts (e.g.,
Cmd+W) could still trigger stale AppKit menu items.Configured shortcut handling is now dispatched earlier (via new
handleConfiguredShortcutKeyEquivalent) from bothNSApplication.sendEventand window key-equivalent paths, before any stale menu fallback runs.Refines
shouldSuppressStaleCmuxMenuShortcutto (1) treat default close shortcuts as stale even when their key is reassigned, and (2) avoid suppressing events owned by current numbered-digit shortcuts. Adds regression tests covering these scenarios, including an end-to-endCmd+Wreassignment against a mocked stale Close Tab menu item.Reviewed by Cursor Bugbot for commit e9e396c. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes #1488: remapped Cmd+W and other Close shortcuts no longer lose to stale menu items, and numbered-digit shortcuts (e.g., Cmd+2) keep working. Configured shortcuts now run before any menu fallback; Close defaults are considered stale once reassigned.
NSApplication.sendEventandNSWindow.performKeyEquivalentvia a sharedhandleConfiguredShortcutKeyEquivalent..closeTab,.closeWorkspace, and.closeWindowdefaults as stale after reassignment; do not suppress current numbered-digit shortcuts.Written for commit e9e396c. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
Bug Fixes
Tests