macos: slide terminal exit and close window don't kill the window

This commit is contained in:
Mitchell Hashimoto
2024-09-28 10:51:14 -07:00
parent 50fb7331af
commit 1977e220f5
2 changed files with 21 additions and 3 deletions

View File

@ -64,9 +64,9 @@ class SlideTerminalController: BaseTerminalController {
override func surfaceTreeDidChange(from: Ghostty.SplitNode?, to: Ghostty.SplitNode?) { override func surfaceTreeDidChange(from: Ghostty.SplitNode?, to: Ghostty.SplitNode?) {
super.surfaceTreeDidChange(from: from, to: to) super.surfaceTreeDidChange(from: from, to: to)
// If our surface tree is now nil then we close our window. // If our surface tree is nil then we slide the window out.
if (to == nil) { if (to == nil) {
self.window?.close() slideOut()
} }
} }
@ -83,7 +83,16 @@ class SlideTerminalController: BaseTerminalController {
func slideIn() { func slideIn() {
guard let window = self.window else { return } guard let window = self.window else { return }
// Animate the window in
slideWindowIn(window: window, from: position) slideWindowIn(window: window, from: position)
// If our surface tree is nil then we initialize a new terminal. The surface
// tree can be nil if for example we run "eixt" in the terminal and force a
// slide out.
if (surfaceTree == nil) {
surfaceTree = .leaf(.init(ghostty.app!, baseConfig: nil))
}
} }
func slideOut() { func slideOut() {
@ -148,4 +157,11 @@ class SlideTerminalController: BaseTerminalController {
windows.first?.makeKeyAndOrderFront(nil) windows.first?.makeKeyAndOrderFront(nil)
} }
} }
// MARK: First Responder
@IBAction override func closeWindow(_ sender: Any) {
// Instead of closing the window, we slide it out.
slideOut()
}
} }

View File

@ -229,10 +229,12 @@ class BaseTerminalController: NSWindowController,
} }
func windowWillClose(_ notification: Notification) { func windowWillClose(_ notification: Notification) {
guard let window else { return }
// I don't know if this is required anymore. We previously had a ref cycle between // I don't know if this is required anymore. We previously had a ref cycle between
// the view and the window so we had to nil this out to break it but I think this // the view and the window so we had to nil this out to break it but I think this
// may now be resolved. We should verify that no memory leaks and we can remove this. // may now be resolved. We should verify that no memory leaks and we can remove this.
self.window?.contentView = nil window.contentView = nil
} }
func windowDidBecomeKey(_ notification: Notification) { func windowDidBecomeKey(_ notification: Notification) {