diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index f5b500b70..9454b1f86 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -458,8 +458,12 @@ class BaseTerminalController: NSWindowController, replaceSurfaceTree( surfaceTree.removing(node), - moveFocusTo: nextFocus, - moveFocusFrom: focusedSurface, + // When a non-focused surface is removed and this window stays as the key window, + // we should refocus the `focusedSurface` to make sure the window's firstResponder remains as it is. + // + // This is a weird workaround, since `resignFirstResponder` wasn't called on `focusedSurface` after drag, + // but the first responder became the window itself. + moveFocusTo: nextFocus ?? focusedSurface, undoAction: "Close Terminal" ) }