diff --git a/TablePro/Core/Services/Infrastructure/TabWindowController.swift b/TablePro/Core/Services/Infrastructure/TabWindowController.swift index aac5df115..b0f8f00c0 100644 --- a/TablePro/Core/Services/Infrastructure/TabWindowController.swift +++ b/TablePro/Core/Services/Infrastructure/TabWindowController.swift @@ -20,9 +20,10 @@ import AppKit import os import SwiftUI -/// NSWindow subclass that routes Cmd+W (performClose:) through the coordinator's -/// closeTab() instead of AppKit's default close. This ensures the last tab clears -/// to the empty "No tabs open" state instead of closing the entire window. +/// NSWindow subclass that routes the standard tab-related responder selectors +/// (`performClose:`, `newWindowForTab:`) through the coordinator. Menus and +/// toolbar buttons reach this via `NSApp.sendAction(_:to:nil:from:)`, the same +/// pattern AppKit uses for `selectNextTab:` and `selectPreviousTab:`. @MainActor private final class EditorWindow: NSWindow { override func performClose(_ sender: Any?) { @@ -33,6 +34,15 @@ private final class EditorWindow: NSWindow { super.performClose(sender) } } + + override func newWindowForTab(_ sender: Any?) { + guard let coordinator = MainContentCoordinator.coordinator(forWindow: self), + let actions = coordinator.commandActions else { + super.newWindowForTab(sender) + return + } + actions.newTab() + } } @MainActor diff --git a/TablePro/TableProApp.swift b/TablePro/TableProApp.swift index a3b5463b3..6e08c8730 100644 --- a/TablePro/TableProApp.swift +++ b/TablePro/TableProApp.swift @@ -211,7 +211,7 @@ struct AppMenuCommands: Commands { CommandGroup(after: .newItem) { Button("New Tab") { - actions?.newTab() + NSApp.sendAction(#selector(NSWindow.newWindowForTab(_:)), to: nil, from: nil) } .optionalKeyboardShortcut(shortcut(for: .newTab)) .disabled(!(actions?.isConnected ?? false))