From 50bbced0c94e586fda68cab1a7299c77947fd9fe Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 11 Dec 2025 16:40:09 -0800 Subject: [PATCH] macos: add title override to restorable state --- .../Features/Terminal/BaseTerminalController.swift | 10 +++++----- .../Sources/Features/Terminal/TerminalRestorable.swift | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 05e3c8142..6336f0f55 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -83,7 +83,7 @@ class BaseTerminalController: NSWindowController, /// An override title for the tab/window set by the user via prompt_tab_title. /// When set, this takes precedence over the computed title from the terminal. - var tabTitleOverride: String? = nil { + var titleOverride: String? = nil { didSet { applyTitleToWindow() } } @@ -344,7 +344,7 @@ class BaseTerminalController: NSWindowController, alert.alertStyle = .informational let textField = NSTextField(frame: NSRect(x: 0, y: 0, width: 250, height: 24)) - textField.stringValue = tabTitleOverride ?? window.title + textField.stringValue = titleOverride ?? window.title alert.accessoryView = textField alert.addButton(withTitle: "OK") @@ -358,9 +358,9 @@ class BaseTerminalController: NSWindowController, let newTitle = textField.stringValue if newTitle.isEmpty { - self.tabTitleOverride = nil + self.titleOverride = nil } else { - self.tabTitleOverride = newTitle + self.titleOverride = newTitle } } } @@ -764,7 +764,7 @@ class BaseTerminalController: NSWindowController, private func applyTitleToWindow() { guard let window else { return } - window.title = tabTitleOverride ?? lastComputedTitle + window.title = titleOverride ?? lastComputedTitle } func pwdDidChange(to: URL?) { diff --git a/macos/Sources/Features/Terminal/TerminalRestorable.swift b/macos/Sources/Features/Terminal/TerminalRestorable.swift index ce13f2620..425f7ffb1 100644 --- a/macos/Sources/Features/Terminal/TerminalRestorable.swift +++ b/macos/Sources/Features/Terminal/TerminalRestorable.swift @@ -4,18 +4,20 @@ import Cocoa class TerminalRestorableState: Codable { static let selfKey = "state" static let versionKey = "version" - static let version: Int = 6 + static let version: Int = 7 let focusedSurface: String? let surfaceTree: SplitTree let effectiveFullscreenMode: FullscreenMode? let tabColor: TerminalTabColor + let titleOverride: String? init(from controller: TerminalController) { self.focusedSurface = controller.focusedSurface?.id.uuidString self.surfaceTree = controller.surfaceTree self.effectiveFullscreenMode = controller.fullscreenStyle?.fullscreenMode self.tabColor = (controller.window as? TerminalWindow)?.tabColor ?? .none + self.titleOverride = controller.titleOverride } init?(coder aDecoder: NSCoder) { @@ -34,6 +36,7 @@ class TerminalRestorableState: Codable { self.focusedSurface = v.value.focusedSurface self.effectiveFullscreenMode = v.value.effectiveFullscreenMode self.tabColor = v.value.tabColor + self.titleOverride = v.value.titleOverride } func encode(with coder: NSCoder) { @@ -100,6 +103,9 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration { // Restore our tab color (window as? TerminalWindow)?.tabColor = state.tabColor + // Restore the tab title override + c.titleOverride = state.titleOverride + // Setup our restored state on the controller // Find the focused surface in surfaceTree if let focusedStr = state.focusedSurface {