macos: fix bugs

This commit is contained in:
Mitchell Hashimoto
2025-12-29 10:46:58 -08:00
parent 19f7b57cd1
commit 7512f6158b
2 changed files with 13 additions and 5 deletions

View File

@@ -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

View File

@@ -285,7 +285,8 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
static func newWindow(
_ ghostty: Ghostty.App,
tree: SplitTree<Ghostty.SurfaceView>,
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(