Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions TablePro/Core/Services/Infrastructure/TabWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TablePro/TableProApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading