From 1977e220f587a03a70d31d6904ca7faaf3416668 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 28 Sep 2024 10:51:14 -0700 Subject: [PATCH] macos: slide terminal exit and close window don't kill the window --- .../SlideTerminalController.swift | 20 +++++++++++++++++-- .../Terminal/BaseTerminalController.swift | 4 +++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift b/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift index 4b5ec05d3..5029b22b0 100644 --- a/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift +++ b/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift @@ -64,9 +64,9 @@ class SlideTerminalController: BaseTerminalController { override func surfaceTreeDidChange(from: Ghostty.SplitNode?, to: Ghostty.SplitNode?) { 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) { - self.window?.close() + slideOut() } } @@ -83,7 +83,16 @@ class SlideTerminalController: BaseTerminalController { func slideIn() { guard let window = self.window else { return } + + // Animate the window in 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() { @@ -148,4 +157,11 @@ class SlideTerminalController: BaseTerminalController { windows.first?.makeKeyAndOrderFront(nil) } } + + // MARK: First Responder + + @IBAction override func closeWindow(_ sender: Any) { + // Instead of closing the window, we slide it out. + slideOut() + } } diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index fec30eecb..4417ce9cc 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -229,10 +229,12 @@ class BaseTerminalController: NSWindowController, } 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 // 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. - self.window?.contentView = nil + window.contentView = nil } func windowDidBecomeKey(_ notification: Notification) {