diff options
| author | Mitchell Hashimoto <m@mitchellh.com> | 2025-09-19 10:15:04 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-19 10:15:04 -0700 |
| commit | 1b6cda2b1046b80df7fa33bb5f4b9dea8863445a (patch) | |
| tree | 6d69c070a873e1774a145998f10131cbc65692ee /macos | |
| parent | 950d3755ff325cf38f474a14298539d180a62db3 (diff) | |
| parent | 6143aa8ce0f28842d7ec0b1a7f1493e54ef82fa5 (diff) | |
macos: "new tab" service should set preferred parent to ensure tab (#8784)
Fixes #8783
Our new tab flow will never have a previously focused window because its
triggered by a service so we need to use the "preferred parent" logic we
have to open this in the last focused window.
Diffstat (limited to 'macos')
| -rw-r--r-- | macos/Sources/Features/Services/ServiceProvider.swift | 5 | ||||
| -rw-r--r-- | macos/Sources/Features/Terminal/TerminalController.swift | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/macos/Sources/Features/Services/ServiceProvider.swift b/macos/Sources/Features/Services/ServiceProvider.swift index f60f94211..f165769a7 100644 --- a/macos/Sources/Features/Services/ServiceProvider.swift +++ b/macos/Sources/Features/Services/ServiceProvider.swift @@ -55,7 +55,10 @@ class ServiceProvider: NSObject { _ = TerminalController.newWindow(delegate.ghostty, withBaseConfig: config) case .tab: - _ = TerminalController.newTab(delegate.ghostty, withBaseConfig: config) + _ = TerminalController.newTab( + delegate.ghostty, + from: TerminalController.preferredParent?.window, + withBaseConfig: config) } } diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 4bb642ea6..779c13d9c 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -184,8 +184,14 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr static var preferredParent: TerminalController? { all.first { $0.window?.isMainWindow ?? false - } ?? all.last + } ?? lastMain ?? all.last } + + // The last controller to be main. We use this when paired with "preferredParent" + // to find the preferred window to attach new tabs, perform actions, etc. We + // always prefer the main window but if there isn't any (because we're triggered + // by something like an App Intent) then we prefer the most previous main. + static private(set) weak var lastMain: TerminalController? = nil /// The "new window" action. static func newWindow( @@ -1036,6 +1042,9 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr if let window { LastWindowPosition.shared.save(window) } + + // Remember our last main + Self.lastMain = self } // Called when the window will be encoded. We handle the data encoding here in the |
