Fix tab titles not being preserved with window-save-state (#8037)

Fixes #7938



https://github.com/user-attachments/assets/766a5d7a-f660-428f-b82b-3eafea83eff3
This commit is contained in:
Mitchell Hashimoto
2025-07-23 16:48:35 -07:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import Cocoa
class TerminalRestorableState: Codable {
static let selfKey = "state"
static let versionKey = "version"
static let version: Int = 3
static let version: Int = 4
let focusedSurface: String?
let surfaceTree: SplitTree<Ghostty.SurfaceView>

View File

@ -1519,6 +1519,8 @@ extension Ghostty {
enum CodingKeys: String, CodingKey {
case pwd
case uuid
case title
case isUserSetTitle
}
required convenience init(from decoder: Decoder) throws {
@ -1533,14 +1535,27 @@ extension Ghostty {
let uuid = UUID(uuidString: try container.decode(String.self, forKey: .uuid))
var config = Ghostty.SurfaceConfiguration()
config.workingDirectory = try container.decode(String?.self, forKey: .pwd)
let savedTitle = try container.decodeIfPresent(String.self, forKey: .title)
let isUserSetTitle = try container.decodeIfPresent(Bool.self, forKey: .isUserSetTitle) ?? false
self.init(app, baseConfig: config, uuid: uuid)
// Restore the saved title after initialization
if let title = savedTitle {
self.title = title
// If this was a user-set title, we need to prevent it from being overwritten
if isUserSetTitle {
self.titleFromTerminal = title
}
}
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(pwd, forKey: .pwd)
try container.encode(uuid.uuidString, forKey: .uuid)
try container.encode(title, forKey: .title)
try container.encode(titleFromTerminal != nil, forKey: .isUserSetTitle)
}
}
}