Repository navigation
Fix Cmd+, settings shortcut routing #3722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2791,6 +2791,61 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { | |
| XCTAssertEqual(workspace.panels.count, panelCountBefore) | ||
| } | ||
|
|
||
| func testCmdCommaOpensSettingsFromWindowWithoutTerminalShortcutContext() { | ||
| guard let appDelegate = AppDelegate.shared else { | ||
| XCTFail("Expected AppDelegate.shared") | ||
| return | ||
| } | ||
|
|
||
| let windowId = appDelegate.createMainWindow() | ||
| defer { closeWindow(withId: windowId) } | ||
|
|
||
| let auxiliaryWindow = NSWindow( | ||
| contentRect: NSRect(x: 0, y: 0, width: 360, height: 240), | ||
| styleMask: [.titled, .closable], | ||
| backing: .buffered, | ||
| defer: false | ||
| ) | ||
| auxiliaryWindow.isReleasedWhenClosed = false | ||
| auxiliaryWindow.identifier = NSUserInterfaceItemIdentifier("cmux.shortcut-routing-test") | ||
| auxiliaryWindow.makeKeyAndOrderFront(nil) | ||
| RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) | ||
| defer { | ||
| auxiliaryWindow.orderOut(nil) | ||
| auxiliaryWindow.close() | ||
| RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) | ||
| } | ||
|
|
||
| var settingsOpenCount = 0 | ||
| #if DEBUG | ||
| SettingsWindowPresenter.resetForTests() | ||
| defer { SettingsWindowPresenter.resetForTests() } | ||
| #endif | ||
| SettingsWindowPresenter.configure(openWindow: { | ||
| settingsOpenCount += 1 | ||
| }) | ||
|
Comment on lines
+2819
to
+2826
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+2819
to
+2826
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Move the 🛡️ Proposed fix var settingsOpenCount = 0
`#if` DEBUG
SettingsWindowPresenter.resetForTests()
+SettingsWindowPresenter.configure(openWindow: {
+ settingsOpenCount += 1
+})
defer { SettingsWindowPresenter.resetForTests() }
`#endif`
-SettingsWindowPresenter.configure(openWindow: {
- settingsOpenCount += 1
-})🤖 Prompt for AI Agents |
||
|
|
||
| guard let event = makeKeyDownEvent( | ||
| key: ",", | ||
| modifiers: [.command], | ||
| keyCode: 43, | ||
| windowNumber: auxiliaryWindow.windowNumber | ||
| ) else { | ||
| XCTFail("Failed to construct Cmd+, event") | ||
| return | ||
| } | ||
|
|
||
| #if DEBUG | ||
| XCTAssertTrue( | ||
| appDelegate.debugHandleCustomShortcut(event: event), | ||
| "Cmd+, should remain app-scoped when the key event comes from a non-terminal window" | ||
| ) | ||
| #else | ||
| XCTFail("debugHandleCustomShortcut is only available in DEBUG") | ||
| #endif | ||
| XCTAssertEqual(settingsOpenCount, 1) | ||
| } | ||
|
|
||
| func testCmdIStillTriggersShowNotificationsShortcut() { | ||
| guard let appDelegate = AppDelegate.shared else { | ||
| XCTFail("Expected AppDelegate.shared") | ||
|
|
||
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.
handleContextIndependentShortcutandcontextIndependentShortcutActionsmust be kept in sync manuallyThe dispatch logic in
handleContextIndependentShortcutand the chord-detection list incontextIndependentShortcutActionsenumerate the same four actions in two separate, unconnected places. If a future change adds a new action to the dispatch function but misses the array (or vice versa), chord-shortcut detection for that action will silently break with no compiler or test coverage to catch it. Consider havinghandleContextIndependentShortcutdriven by the same set declared in the property, or at minimum add a comment explicitly calling out the coupling requirement.Rule Used: Flag Swift fixes that patch symptoms while leaving... (source)