From 03355ca3fc729a4a39d9d456a6609b688df5b174 Mon Sep 17 00:00:00 2001 From: Achieve Date: Wed, 25 Mar 2026 13:26:31 +0800 Subject: [PATCH] Consume Cmd+number shortcuts even when workspace index is out of bounds (#2033) When pressing Cmd+N for a workspace number that doesn't exist, the event was not consumed and fell through to Ghostty's goto_tab binding, which could create a new window. Now the event is always consumed when the digit matches, preventing unintended window creation. Fixes #1970 Co-authored-by: Claude Opus 4.6 (1M context) --- Sources/AppDelegate.swift | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 271cbbf7..d4e4660e 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -9484,18 +9484,21 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent } // Numeric shortcuts for specific workspaces (9 = last workspace) - if let manager = tabManager, - let digit = numberedShortcutDigit( - event: event, - shortcut: KeyboardShortcutSettings.shortcut(for: .selectWorkspaceByNumber) - ), - let targetIndex = WorkspaceShortcutMapper.workspaceIndex(forDigit: digit, workspaceCount: manager.tabs.count) { + // Always consume the event when the digit matches to prevent Ghostty's + // goto_tab fallback from creating a new window when the index is out of bounds. + if let digit = numberedShortcutDigit( + event: event, + shortcut: KeyboardShortcutSettings.shortcut(for: .selectWorkspaceByNumber) + ) { + if let manager = tabManager, + let targetIndex = WorkspaceShortcutMapper.workspaceIndex(forDigit: digit, workspaceCount: manager.tabs.count) { #if DEBUG - dlog( - "shortcut.action name=workspaceDigit digit=\(digit) targetIndex=\(targetIndex) manager=\(debugManagerToken(manager)) \(debugShortcutRouteSnapshot(event: event))" - ) + dlog( + "shortcut.action name=workspaceDigit digit=\(digit) targetIndex=\(targetIndex) manager=\(debugManagerToken(manager)) \(debugShortcutRouteSnapshot(event: event))" + ) #endif - manager.selectTab(at: targetIndex) + manager.selectTab(at: targetIndex) + } return true }