mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macOS: simplify code for new tab
This commit is contained in:
@ -14,6 +14,6 @@ class PrimaryWindowController: NSWindowController {
|
||||
override func newWindowForTab(_ sender: Any?) {
|
||||
guard let window = self.window as? PrimaryWindow else { preconditionFailure("Expected window to be loaded") }
|
||||
guard let manager = self.windowManager else { return }
|
||||
manager.newTabForWindow(window: window)
|
||||
manager.triggerNewTab(for: window)
|
||||
}
|
||||
}
|
||||
|
@ -78,15 +78,16 @@ class PrimaryWindowManager {
|
||||
newWindow.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
func newTabForWindow(window: PrimaryWindow) {
|
||||
// triggerNewTab tells the Zig core code to create a new tab, which then calls
|
||||
// back into Swift code.
|
||||
func triggerNewTab(for window: PrimaryWindow) {
|
||||
guard let surface = window.focusedSurfaceWrapper.surface else { return }
|
||||
ghostty.newTab(surface: surface)
|
||||
}
|
||||
|
||||
func newTab() {
|
||||
if mainWindow != nil {
|
||||
guard let window = mainWindow as? PrimaryWindow else { return }
|
||||
self.newTabForWindow(window: window)
|
||||
if let window = mainWindow as? PrimaryWindow {
|
||||
self.triggerNewTab(for: window)
|
||||
} else {
|
||||
self.addNewWindow()
|
||||
}
|
||||
@ -99,13 +100,7 @@ class PrimaryWindowManager {
|
||||
let fontSizeAny = notification.userInfo?[Ghostty.Notification.NewTabKey]
|
||||
let fontSize = fontSizeAny as? UInt8
|
||||
|
||||
if fontSize != nil {
|
||||
// Add the new tab to the window with the given font size.
|
||||
self.addNewTab(to: window, withFontSize: fontSize)
|
||||
} else {
|
||||
// No font size specified, just add new tab.
|
||||
self.addNewTab(to: window)
|
||||
}
|
||||
}
|
||||
|
||||
private func addNewTab(to window: NSWindow, withFontSize fontSize: UInt8? = nil) {
|
||||
|
Reference in New Issue
Block a user