From 7512f6158bbfddd88411a17735deba77f08ecf0a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Dec 2025 10:46:58 -0800 Subject: [PATCH] macos: fix bugs --- .../Features/Terminal/BaseTerminalController.swift | 9 ++++++--- macos/Sources/Features/Terminal/TerminalController.swift | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index c34119561..e7caf70a9 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -734,7 +734,9 @@ class BaseTerminalController: NSWindowController, // it is already a single split. guard surfaceTree.isSplit else { return } - // If we are removing our focused surface then we move it. + // If we are removing our focused surface then we move it. We need to + // keep track of our old one so undo sends focus back to the right place. + let oldFocusedSurface = focusedSurface if focusedSurface == target { focusedSurface = findNextFocusTargetAfterClosing(node: targetNode) } @@ -752,11 +754,12 @@ class BaseTerminalController: NSWindowController, undoManager?.endUndoGrouping() } - replaceSurfaceTree(removedTree, moveFocusFrom: focusedSurface) + replaceSurfaceTree(removedTree, moveFocusFrom: oldFocusedSurface) _ = TerminalController.newWindow( ghostty, tree: newTree, - position: notification.userInfo?[Notification.Name.ghosttySurfaceDragEndedNoTargetPointKey] as? NSPoint) + position: notification.userInfo?[Notification.Name.ghosttySurfaceDragEndedNoTargetPointKey] as? NSPoint, + confirmUndo: false) } // MARK: Local Events diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 021b9f394..fbd215e2b 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -285,7 +285,8 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr static func newWindow( _ ghostty: Ghostty.App, tree: SplitTree, - position: NSPoint? = nil + position: NSPoint? = nil, + confirmUndo: Bool = true, ) -> TerminalController { let c = TerminalController.init(ghostty, withSurfaceTree: tree) @@ -321,7 +322,11 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr expiresAfter: c.undoExpiration ) { target in undoManager.disableUndoRegistration { - target.closeWindow(nil) + if confirmUndo { + target.closeWindow(nil) + } else { + target.closeWindowImmediately() + } } undoManager.registerUndo(