mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
Fix tab titles not being preserved with window-save-state
Add serialization for tab titles in SurfaceView to persist user-set titles across app restarts. Bump TerminalRestorableState version to 4 to handle the new format.
This commit is contained in:
@ -4,7 +4,7 @@ import Cocoa
|
|||||||
class TerminalRestorableState: Codable {
|
class TerminalRestorableState: Codable {
|
||||||
static let selfKey = "state"
|
static let selfKey = "state"
|
||||||
static let versionKey = "version"
|
static let versionKey = "version"
|
||||||
static let version: Int = 3
|
static let version: Int = 4
|
||||||
|
|
||||||
let focusedSurface: String?
|
let focusedSurface: String?
|
||||||
let surfaceTree: SplitTree<Ghostty.SurfaceView>
|
let surfaceTree: SplitTree<Ghostty.SurfaceView>
|
||||||
|
@ -1519,6 +1519,8 @@ extension Ghostty {
|
|||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case pwd
|
case pwd
|
||||||
case uuid
|
case uuid
|
||||||
|
case title
|
||||||
|
case isUserSetTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
required convenience init(from decoder: Decoder) throws {
|
required convenience init(from decoder: Decoder) throws {
|
||||||
@ -1533,14 +1535,27 @@ extension Ghostty {
|
|||||||
let uuid = UUID(uuidString: try container.decode(String.self, forKey: .uuid))
|
let uuid = UUID(uuidString: try container.decode(String.self, forKey: .uuid))
|
||||||
var config = Ghostty.SurfaceConfiguration()
|
var config = Ghostty.SurfaceConfiguration()
|
||||||
config.workingDirectory = try container.decode(String?.self, forKey: .pwd)
|
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)
|
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 {
|
func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(pwd, forKey: .pwd)
|
try container.encode(pwd, forKey: .pwd)
|
||||||
try container.encode(uuid.uuidString, forKey: .uuid)
|
try container.encode(uuid.uuidString, forKey: .uuid)
|
||||||
|
try container.encode(title, forKey: .title)
|
||||||
|
try container.encode(titleFromTerminal != nil, forKey: .isUserSetTitle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user