From 69f5c98bc5025ebe81b97094696967712838d434 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 10:37:18 -0700 Subject: [PATCH 01/13] fix: restore shortcut chord routing in CI --- Sources/AppDelegate.swift | 10 ++++++++++ cmuxTests/AppDelegateShortcutRoutingTests.swift | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 45709fa037be..9ba74172936b 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -11713,6 +11713,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent return true } + if activeConfiguredShortcutChordPrefixForCurrentEvent == nil { + let focusContext = shortcutEventFocusContext(event) + let availableChordActions = configuredShortcutChordActions.filter { action in + action.shortcutContext.isAlwaysAvailable || action.shortcutContext.isAvailable(focusContext) + } + if armConfiguredShortcutChordIfNeeded(event: event, actions: availableChordActions) { + return true + } + } + // Fast path for normal typing and terminal navigation keys (for example Up-arrow // history): after command-palette/notification handling and browser omnibar // arrow navigation above, most plain key events have no app-level shortcut behavior. diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index 9bbd0c11749f..a384e74901af 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -344,6 +344,9 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { fallbackPath: nil, startWatching: false ) + #if DEBUG + appDelegate.debugResetShortcutRoutingStateForTesting() + #endif window.makeKeyAndOrderFront(nil) RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) @@ -1839,6 +1842,16 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { AppDelegate.installWindowResponderSwizzlesForTesting() + let windowId = appDelegate.createMainWindow() + defer { closeWindow(withId: windowId) } + + guard let mainWindow = window(withId: windowId) else { + XCTFail("Expected test main window") + return + } + mainWindow.makeKeyAndOrderFront(nil) + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) + let previousMainMenu = NSApp.mainMenu let probeWindow = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 320, height: 240), @@ -1846,6 +1859,7 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { backing: .buffered, defer: false ) + probeWindow.isReleasedWhenClosed = false probeWindow.identifier = NSUserInterfaceItemIdentifier("cmux.browser-popup") let contentView = NSView(frame: probeWindow.contentRect(forFrameRect: probeWindow.frame)) let probeView = GhosttyCommandEquivalentProbeView(frame: NSRect(x: 0, y: 0, width: 200, height: 120)) @@ -1854,6 +1868,8 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { defer { NSApp.mainMenu = previousMainMenu probeWindow.orderOut(nil) + probeWindow.close() + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) } let staleMenu = NSMenu(title: "Test") From 6e51be95f682369e7bca4ca8491ef888f491a616 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 10:49:39 -0700 Subject: [PATCH 02/13] fix: compute shortcut chord actions live --- Sources/AppDelegate.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 9ba74172936b..6f5f2e960c1e 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -688,7 +688,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent private var pendingConfiguredShortcutChord: PendingConfiguredShortcutChord? var activeConfiguredShortcutChordPrefixForCurrentEvent: ShortcutStroke? var shortcutEventFocusContextCache: ShortcutEventFocusContextCache? - private var configuredShortcutChordActions: [KeyboardShortcutSettings.Action] = [] private var ghosttyConfigObserver: NSObjectProtocol? private var ghosttyGotoSplitLeftShortcut: StoredShortcut? private var ghosttyGotoSplitRightShortcut: StoredShortcut? @@ -11014,7 +11013,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent private func installShortcutDefaultsObserver() { guard shortcutDefaultsObserver == nil else { return } - refreshConfiguredShortcutChordActions() shortcutDefaultsObserver = NotificationCenter.default.addObserver( forName: KeyboardShortcutSettings.didChangeNotification, object: nil, @@ -11033,13 +11031,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent } private func handleShortcutDefaultsDidChange() { - refreshConfiguredShortcutChordActions() clearConfiguredShortcutChordState() scheduleSplitButtonTooltipRefreshAcrossWorkspaces() } - private func refreshConfiguredShortcutChordActions() { - configuredShortcutChordActions = KeyboardShortcutSettings.Action.allCases.filter { action in + private func currentConfiguredShortcutChordActions() -> [KeyboardShortcutSettings.Action] { + KeyboardShortcutSettings.Action.allCases.filter { action in // System-wide hotkeys are dispatched via Carbon RegisterEventHotKey // and never routed through AppKit's local key handler. If a managed // cmux.json entry somehow stores one as a chord, arming the prefix @@ -11715,7 +11712,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent if activeConfiguredShortcutChordPrefixForCurrentEvent == nil { let focusContext = shortcutEventFocusContext(event) - let availableChordActions = configuredShortcutChordActions.filter { action in + let availableChordActions = currentConfiguredShortcutChordActions().filter { action in action.shortcutContext.isAlwaysAvailable || action.shortcutContext.isAvailable(focusContext) } if armConfiguredShortcutChordIfNeeded(event: event, actions: availableChordActions) { @@ -13214,7 +13211,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent } func debugResetShortcutRoutingStateForTesting() { - refreshConfiguredShortcutChordActions() clearConfiguredShortcutChordState() shortcutEventFocusContextCache = nil } @@ -13412,7 +13408,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent shortcuts: [StoredShortcut] = [] ) -> Bool { var seen = Set() - let configuredShortcuts = (actions ?? configuredShortcutChordActions).map { + let configuredShortcuts = (actions ?? currentConfiguredShortcutChordActions()).map { KeyboardShortcutSettings.shortcut(for: $0) } + shortcuts for shortcut in configuredShortcuts { From b6bc7094b2829f0146a98d9d7c78cd8cb4272dbb Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 10:59:22 -0700 Subject: [PATCH 03/13] fix: stabilize shortcut routing CI tests --- Sources/AppDelegate.swift | 14 ++++----- ...pDelegateEqualizeSplitsShortcutTests.swift | 30 ++++++++++++++++++- .../AppDelegateShortcutRoutingTests.swift | 21 ++++++++++++- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 6f5f2e960c1e..9b9bff2cca13 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -11710,6 +11710,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent return true } + // Fast path for normal typing and terminal navigation keys (for example Up-arrow + // history): after command-palette/notification handling and browser omnibar + // arrow navigation above, most plain key events have no app-level shortcut behavior. + if shouldBypassPlainKeyShortcutRouting(event: event, normalizedFlags: normalizedFlags) { + return false + } + if activeConfiguredShortcutChordPrefixForCurrentEvent == nil { let focusContext = shortcutEventFocusContext(event) let availableChordActions = currentConfiguredShortcutChordActions().filter { action in @@ -11720,13 +11727,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent } } - // Fast path for normal typing and terminal navigation keys (for example Up-arrow - // history): after command-palette/notification handling and browser omnibar - // arrow navigation above, most plain key events have no app-level shortcut behavior. - if shouldBypassPlainKeyShortcutRouting(event: event, normalizedFlags: normalizedFlags) { - return false - } - let configuredCmuxShortcutContext = preferredMainWindowContextForShortcutRouting(event: event) let configuredCmuxShortcutActions = configuredCmuxShortcutActions(for: configuredCmuxShortcutContext) diff --git a/cmuxTests/AppDelegateEqualizeSplitsShortcutTests.swift b/cmuxTests/AppDelegateEqualizeSplitsShortcutTests.swift index 302525c1da99..58623a5acd6b 100644 --- a/cmuxTests/AppDelegateEqualizeSplitsShortcutTests.swift +++ b/cmuxTests/AppDelegateEqualizeSplitsShortcutTests.swift @@ -113,6 +113,9 @@ final class AppDelegateEqualizeSplitsShortcutTests: XCTestCase { XCTFail("Expected cached layout snapshot after seeding split geometry") return } + let expectedEqualizedPositions = shortcutRoutingExpectedEqualizedDividerPositions( + in: workspace.bonsplitController.treeSnapshot() + ) guard let event = makeKeyDownEvent(key: "=", modifiers: [.command, .control], keyCode: 24, windowNumber: window.windowNumber) else { XCTFail("Failed to construct Cmd+Ctrl+= event") @@ -130,7 +133,11 @@ final class AppDelegateEqualizeSplitsShortcutTests: XCTestCase { let equalizedSplits = shortcutRoutingSplitNodes(in: workspace.bonsplitController.treeSnapshot()) XCTAssertEqual(equalizedSplits.count, seededSplits.count) for split in equalizedSplits { - XCTAssertEqual(split.dividerPosition, 0.5, accuracy: 0.000_1) + guard let expectedPosition = expectedEqualizedPositions[split.id] else { + XCTFail("Expected equalized split ID to remain present") + continue + } + XCTAssertEqual(split.dividerPosition, expectedPosition, accuracy: 0.000_1) } let liveEqualizedLayout = workspace.bonsplitController.layoutSnapshot() @@ -154,6 +161,27 @@ final class AppDelegateEqualizeSplitsShortcutTests: XCTestCase { } } + private func shortcutRoutingExpectedEqualizedDividerPositions(in node: ExternalTreeNode) -> [String: Double] { + var positionsBySplitId: [String: Double] = [:] + + @discardableResult + func collectLeafCount(_ node: ExternalTreeNode) -> Int { + switch node { + case .pane: + return 1 + case .split(let split): + let firstLeafCount = collectLeafCount(split.first) + let secondLeafCount = collectLeafCount(split.second) + let totalLeafCount = firstLeafCount + secondLeafCount + positionsBySplitId[split.id] = Double(firstLeafCount) / Double(totalLeafCount) + return totalLeafCount + } + } + + collectLeafCount(node) + return positionsBySplitId + } + private func shortcutRoutingPaneFramesById(in snapshot: LayoutSnapshot) -> [String: PixelRect] { Dictionary(uniqueKeysWithValues: snapshot.panes.map { ($0.paneId, $0.frame) }) } diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index a384e74901af..2e1722a093af 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -823,7 +823,9 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { ) appDelegate.debugCreateMainWindowSourceIsNativeFullScreenOverride = nil - RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) + waitUntil(timeout: 1.0) { + !newWindow.collectionBehavior.contains(.fullScreenDisallowsTiling) + } XCTAssertFalse( newWindow.collectionBehavior.contains(.fullScreenDisallowsTiling), @@ -1694,12 +1696,16 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { } let windowId = appDelegate.createMainWindow() + defer { closeWindow(withId: windowId) } guard let targetWindow = window(withId: windowId) else { XCTFail("Expected test window") return } + targetWindow.makeKeyAndOrderFront(nil) + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) appDelegate.debugCloseMainWindowConfirmationHandler = { _ in true } + defer { appDelegate.debugCloseMainWindowConfirmationHandler = nil } guard let event = makeKeyDownEvent( key: "w", @@ -3343,6 +3349,8 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { XCTFail("Expected focused browser panel") return } + window.makeKeyAndOrderFront(nil) + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) let field = OmnibarNativeTextField(frame: NSRect(x: 8, y: 8, width: 240, height: 24)) field.identifier = browserOmnibarTextFieldIdentifier @@ -4240,6 +4248,8 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { XCTFail("Expected test window") return } + window.makeKeyAndOrderFront(nil) + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) let overlayContainer = NSView(frame: contentView.bounds) overlayContainer.identifier = commandPaletteOverlayContainerIdentifier @@ -6084,6 +6094,8 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { XCTFail("Expected focused terminal surface") return } + window.makeKeyAndOrderFront(nil) + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) appDelegate.noteTerminalKeyboardFocusIntent(workspaceId: workspace.id, panelId: terminalPanel.id, in: window) @@ -6491,6 +6503,13 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) } + private func waitUntil(timeout: TimeInterval, condition: () -> Bool) { + let deadline = Date(timeIntervalSinceNow: timeout) + while !condition(), Date() < deadline { + RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.01)) + } + } + private func restoreDefaultsValue(_ value: Any?, forKey key: String, defaults: UserDefaults) { if let value { defaults.set(value, forKey: key) From b30f0f11c560948f209492d9cead1799dfd03269 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 11:08:46 -0700 Subject: [PATCH 04/13] fix: respect shortcut context when arming config chords --- Sources/AppDelegate.swift | 1 + cmuxTests/AppDelegateShortcutRoutingTests.swift | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 9b9bff2cca13..faf72431f5f2 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -11733,6 +11733,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent if activeConfiguredShortcutChordPrefixForCurrentEvent == nil, armConfiguredShortcutChordIfNeeded( event: event, + actions: [], shortcuts: configuredCmuxShortcutActions.compactMap(\.shortcut) ) { return true diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index 2e1722a093af..e3e7053f428a 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -1723,7 +1723,9 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { XCTFail("debugHandleCustomShortcut is only available in DEBUG") #endif - RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) + waitUntil(timeout: 1.0) { + self.window(withId: windowId) == nil + } XCTAssertNil(self.window(withId: windowId), "Confirming Cmd+Ctrl+W should close the window") } @@ -4284,6 +4286,12 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { } defer { NotificationCenter.default.removeObserver(moveToken) } + window.displayIfNeeded() + XCTAssertTrue( + window.makeFirstResponder(fieldEditor), + "Expected command palette field editor to own first responder" + ) + guard let downArrowEvent = makeKeyDownEvent( key: String(UnicodeScalar(NSDownArrowFunctionKey)!), modifiers: [], From 86fb05c8063be454e03c3bf2ac1bfa4dc117891e Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 11:15:29 -0700 Subject: [PATCH 05/13] fix: require explicit chord arming actions --- Sources/AppDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index faf72431f5f2..378ad574e0df 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -13405,11 +13405,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent private func armConfiguredShortcutChordIfNeeded( event: NSEvent, - actions: [KeyboardShortcutSettings.Action]? = nil, + actions: [KeyboardShortcutSettings.Action], shortcuts: [StoredShortcut] = [] ) -> Bool { var seen = Set() - let configuredShortcuts = (actions ?? currentConfiguredShortcutChordActions()).map { + let configuredShortcuts = actions.map { KeyboardShortcutSettings.shortcut(for: $0) } + shortcuts for shortcut in configuredShortcuts { From 83f39a829edca01787b5e30c36bf418d854c76f8 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 11:50:42 -0700 Subject: [PATCH 06/13] fix: stabilize omnibar shortcut focus fixture --- cmuxTests/AppDelegateShortcutRoutingTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index e3e7053f428a..fe17527250e2 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -3366,8 +3366,8 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { field.removeFromSuperview() } - _ = browserPanel.requestAddressBarFocus() - NotificationCenter.default.post(name: .browserDidFocusAddressBar, object: browserPanelId) + XCTAssertTrue(appDelegate.requestBrowserAddressBarFocus(panelId: browserPanelId)) + XCTAssertEqual(appDelegate.focusedBrowserAddressBarPanelId(), browserPanelId) _ = window.makeFirstResponder(nil) XCTAssertTrue(window.firstResponder === window) From 19bfe4e94e09d78003537cca7b75b5595d7f4ec4 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 12:05:42 -0700 Subject: [PATCH 07/13] fix: stabilize remaining shortcut routing CI tests --- Sources/AppDelegate.swift | 5 ++++- cmuxTests/AppDelegateShortcutRoutingTests.swift | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 378ad574e0df..e5f50f270b79 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -7403,7 +7403,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent } if shouldTemporarilyDisallowFullScreenTiling { DispatchQueue.main.async { [weak window] in - window?.collectionBehavior.remove(.fullScreenDisallowsTiling) + guard let window else { return } + var behavior = window.collectionBehavior + behavior.remove(.fullScreenDisallowsTiling) + window.collectionBehavior = behavior } } if let explicitInitialFrame { diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index fe17527250e2..abbff1dae12b 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -6103,6 +6103,17 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { return } window.makeKeyAndOrderFront(nil) + window.displayIfNeeded() + terminalPanel.hostedView.setVisibleInUI(true) + terminalPanel.hostedView.setActive(true) + terminalPanel.hostedView.moveFocus() + waitUntil(timeout: 1.0) { + terminalPanel.hostedView.isSurfaceViewFirstResponder() + } + XCTAssertTrue( + terminalPanel.hostedView.isSurfaceViewFirstResponder(), + "Expected terminal surface to own first responder before Cmd+F" + ) RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) appDelegate.noteTerminalKeyboardFocusIntent(workspaceId: workspace.id, panelId: terminalPanel.id, in: window) @@ -6123,6 +6134,9 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { XCTFail("debugHandleCustomShortcut is only available in DEBUG") #endif + waitUntil(timeout: 1.0) { + terminalPanel.searchState != nil + } XCTAssertNotNil(terminalPanel.searchState, "Cmd+F from terminal focus should create terminal search state") } From 0fdb3bd66e8dc7dcc9f1f25f00c36e7f43cefb55 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 12:14:54 -0700 Subject: [PATCH 08/13] fix: stabilize command palette and window close tests --- Sources/AppDelegate.swift | 2 +- cmuxTests/AppDelegateShortcutRoutingTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index e5f50f270b79..d1ebc6a5a42c 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -5162,7 +5162,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent return true } guard confirmCloseMainWindow(window) else { return true } - window.performClose(nil) + window.close() return true } diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index abbff1dae12b..91666fe9e7c9 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -4296,7 +4296,7 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { key: String(UnicodeScalar(NSDownArrowFunctionKey)!), modifiers: [], keyCode: 125, - windowNumber: window.windowNumber + windowNumber: 0 ) else { XCTFail("Failed to construct Down Arrow event") return From 03ec8775ae8e682bde5f147b5d5dacc0125a1f97 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 12:22:50 -0700 Subject: [PATCH 09/13] fix: harden shortcut routing test fixtures --- cmuxTests/AppDelegateShortcutRoutingTests.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmuxTests/AppDelegateShortcutRoutingTests.swift b/cmuxTests/AppDelegateShortcutRoutingTests.swift index 91666fe9e7c9..920e91362dc3 100644 --- a/cmuxTests/AppDelegateShortcutRoutingTests.swift +++ b/cmuxTests/AppDelegateShortcutRoutingTests.swift @@ -1724,10 +1724,13 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { #endif waitUntil(timeout: 1.0) { - self.window(withId: windowId) == nil + self.window(withId: windowId)?.isVisible != true } - XCTAssertNil(self.window(withId: windowId), "Confirming Cmd+Ctrl+W should close the window") + XCTAssertFalse( + self.window(withId: windowId)?.isVisible == true, + "Confirming Cmd+Ctrl+W should close the window" + ) } // NOTE: This test is skipped in CI via -skip-testing in ci.yml because closing @@ -4253,11 +4256,12 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { window.makeKeyAndOrderFront(nil) RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.05)) - let overlayContainer = NSView(frame: contentView.bounds) + let overlayHost = contentView.superview ?? contentView + let overlayContainer = NSView(frame: overlayHost.bounds) overlayContainer.identifier = commandPaletteOverlayContainerIdentifier overlayContainer.alphaValue = 1 overlayContainer.isHidden = false - contentView.addSubview(overlayContainer) + overlayHost.addSubview(overlayContainer) let fieldEditor = CommandPaletteMarkedTextFieldEditor(frame: NSRect(x: 0, y: 0, width: 200, height: 24)) fieldEditor.isFieldEditor = true @@ -4296,7 +4300,7 @@ final class AppDelegateShortcutRoutingTests: XCTestCase { key: String(UnicodeScalar(NSDownArrowFunctionKey)!), modifiers: [], keyCode: 125, - windowNumber: 0 + windowNumber: window.windowNumber ) else { XCTFail("Failed to construct Down Arrow event") return From 0e4c639844e633685c8f699ad6ffbe39dc413055 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 12:24:46 -0700 Subject: [PATCH 10/13] fix: preserve main window close teardown --- Sources/AppDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index d1ebc6a5a42c..e5f50f270b79 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -5162,7 +5162,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent return true } guard confirmCloseMainWindow(window) else { return true } - window.close() + window.performClose(nil) return true } From 051fa6cac1fd20364e69e5b3ab875f47e3618c34 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 13:01:32 -0700 Subject: [PATCH 11/13] fix: address remaining shortcut CI hangs --- Sources/AppDelegate.swift | 22 +++++++++++++------- Sources/TabManager.swift | 9 +++++--- Sources/Update/UpdateTitlebarAccessory.swift | 6 ++++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index e5f50f270b79..c39d923a63be 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -6242,8 +6242,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent case .rightSidebarFileSearch: result = context.keyboardFocusCoordinator.focusFileSearch() case .mainPanelFind: - context.tabManager.startSearch() - result = context.tabManager.isFindVisible + result = context.tabManager.startSearch() case .none: result = false } @@ -7402,11 +7401,20 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent ) } if shouldTemporarilyDisallowFullScreenTiling { - DispatchQueue.main.async { [weak window] in + let clearFullScreenTilingOptOut: () -> Void = { [weak window] in guard let window else { return } - var behavior = window.collectionBehavior - behavior.remove(.fullScreenDisallowsTiling) - window.collectionBehavior = behavior + window.collectionBehavior.remove(.fullScreenDisallowsTiling) + if window.collectionBehavior.contains(.fullScreenDisallowsTiling) { + var behavior = window.collectionBehavior + behavior.remove(.fullScreenDisallowsTiling) + window.collectionBehavior = behavior + } + } + RunLoop.main.perform { + clearFullScreenTilingOptOut() + } + DispatchQueue.main.async { + clearFullScreenTilingOptOut() } } if let explicitInitialFrame { @@ -11825,7 +11833,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent // deferring the toggle, NSAnimationContext implicitly animates the // layout change. let preferredWindow = mainWindowForShortcutEvent(event) ?? event.window ?? NSApp.keyWindow ?? NSApp.mainWindow - Task { @MainActor [weak self, weak preferredWindow] in + DispatchQueue.main.async { [weak self, weak preferredWindow] in _ = self?.toggleRightSidebarInActiveMainWindow(preferredWindow: preferredWindow) } return true diff --git a/Sources/TabManager.swift b/Sources/TabManager.swift index 87b9f79f3b7b..684bc1cae6e8 100644 --- a/Sources/TabManager.swift +++ b/Sources/TabManager.swift @@ -1974,7 +1974,8 @@ class TabManager: ObservableObject { selectedTerminalPanel?.hasSelection() == true } - func startSearch() { + @discardableResult + func startSearch() -> Bool { if let panel = selectedTerminalPanel { let hadExistingSearch = panel.searchState != nil panel.hostedView.preparePanelFocusIntentForActivation(.findField) @@ -1994,9 +1995,11 @@ class TabManager: ObservableObject { "firstResponder=\(String(describing: panel.surface.uiWindow?.firstResponder))" ) #endif - return + return handled } - focusedBrowserPanel?.startFind() + guard let browserPanel = focusedBrowserPanel else { return false } + browserPanel.startFind() + return browserPanel.searchState != nil } func searchSelection() { diff --git a/Sources/Update/UpdateTitlebarAccessory.swift b/Sources/Update/UpdateTitlebarAccessory.swift index 9cd7f5e6f370..01ba988fa028 100644 --- a/Sources/Update/UpdateTitlebarAccessory.swift +++ b/Sources/Update/UpdateTitlebarAccessory.swift @@ -1843,7 +1843,8 @@ final class UpdateTitlebarAccessoryController { queue: .main ) { [weak self] notification in guard let window = notification.object as? NSWindow else { return } - Task { @MainActor [weak self] in + Task { @MainActor [weak self, weak window] in + guard let window else { return } self?.attachIfNeeded(to: window) } }) @@ -1854,7 +1855,8 @@ final class UpdateTitlebarAccessoryController { queue: .main ) { [weak self] notification in guard let window = notification.object as? NSWindow else { return } - Task { @MainActor [weak self] in + Task { @MainActor [weak self, weak window] in + guard let window else { return } self?.attachIfNeeded(to: window) } }) From fe5efcf225426335c84e9645cf0b58c9193f1088 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 13:32:23 -0700 Subject: [PATCH 12/13] fix: preserve managed shortcut parsing edge cases --- Sources/KeyboardShortcutSettings.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/KeyboardShortcutSettings.swift b/Sources/KeyboardShortcutSettings.swift index 2771d6a66634..82a840b3cae0 100644 --- a/Sources/KeyboardShortcutSettings.swift +++ b/Sources/KeyboardShortcutSettings.swift @@ -456,7 +456,13 @@ enum KeyboardShortcutSettings { return normalized } - return usesNumberedDigitMatching || self == .showHideAllWindows || self == .globalSearch ? nil : shortcut + // Preserve invalid settings-file values for the show/hide hotkey so managed + // configuration remains visible instead of silently falling back to defaults. + // Runtime registration still rejects unsupported Carbon hotkey shapes. + if usesNumberedDigitMatching || self == .globalSearch { + return nil + } + return shortcut } func resolvedRecordedShortcutIgnoringConflicts(_ shortcut: StoredShortcut, checkingSystemWideConflicts: Bool = true) -> RecordedShortcutResolution { @@ -2276,7 +2282,8 @@ extension StoredShortcut { private static func isUnboundConfigToken(_ rawValue: String) -> Bool { if rawValue.isEmpty { return true } let normalized = rawValue.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() - return normalized.isEmpty || normalized == "none" || normalized == "clear" || normalized == "unbound" || normalized == "disabled" + guard !normalized.isEmpty else { return false } + return normalized == "none" || normalized == "clear" || normalized == "unbound" || normalized == "disabled" } } From cd9b82c3322122bdf5cffdf41d5111a8093bec3c Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 20 May 2026 13:40:25 -0700 Subject: [PATCH 13/13] fix: distinguish space shortcut from whitespace clear --- Sources/KeyboardShortcutSettings.swift | 5 +++-- cmuxTests/KeyboardShortcutSpaceKeyTests.swift | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/KeyboardShortcutSettings.swift b/Sources/KeyboardShortcutSettings.swift index 82a840b3cae0..6686e0a82521 100644 --- a/Sources/KeyboardShortcutSettings.swift +++ b/Sources/KeyboardShortcutSettings.swift @@ -2180,7 +2180,7 @@ extension ShortcutStroke { private static func parseConfigKeyToken(_ rawValue: String) -> String? { let trimmed = rawValue.trimmingCharacters(in: .whitespacesAndNewlines) if trimmed.isEmpty { - return !rawValue.isEmpty && rawValue.allSatisfy { $0 == " " } ? "space" : nil + return rawValue == " " ? "space" : nil } let lowered = trimmed.lowercased() @@ -2281,8 +2281,9 @@ extension StoredShortcut { private static func isUnboundConfigToken(_ rawValue: String) -> Bool { if rawValue.isEmpty { return true } + if rawValue == " " { return false } let normalized = rawValue.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() - guard !normalized.isEmpty else { return false } + guard !normalized.isEmpty else { return true } return normalized == "none" || normalized == "clear" || normalized == "unbound" || normalized == "disabled" } } diff --git a/cmuxTests/KeyboardShortcutSpaceKeyTests.swift b/cmuxTests/KeyboardShortcutSpaceKeyTests.swift index 31d6a9eb594e..7ffd4363b10c 100644 --- a/cmuxTests/KeyboardShortcutSpaceKeyTests.swift +++ b/cmuxTests/KeyboardShortcutSpaceKeyTests.swift @@ -45,6 +45,9 @@ final class KeyboardShortcutSpaceKeyTests: XCTestCase { XCTAssertEqual(StoredShortcut.parseConfig("cmd+shift+spacebar")?.configIdentifier, "cmd+shift+space") XCTAssertEqual(StoredShortcut.parseConfig("cmd+shift+ ")?.configIdentifier, "cmd+shift+space") XCTAssertEqual(StoredShortcut.parseConfig(" ")?.configIdentifier, "space") + XCTAssertEqual(StoredShortcut.parseConfig(" "), .unbound) + XCTAssertEqual(StoredShortcut.parseConfig("\t"), .unbound) + XCTAssertNil(StoredShortcut.parseConfig("cmd+shift+ ")) } func testSettingsFileStoreParsesSpaceShortcutBinding() throws {