Share last-surface close handling across close actions
This commit is contained in:
parent
3cfa1f1191
commit
9eefc80e32
4 changed files with 41 additions and 24 deletions
|
|
@ -946,6 +946,7 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
|
||||
/// Callback used by TabManager to capture recently closed browser panels for Cmd+Shift+T restore.
|
||||
var onClosedBrowserPanel: ((ClosedBrowserPanelRestoreSnapshot) -> Void)?
|
||||
weak var owningTabManager: TabManager?
|
||||
|
||||
|
||||
// Closing tabs mutates split layout immediately; terminal views handle their own AppKit
|
||||
|
|
@ -4114,6 +4115,19 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
// MARK: - BonsplitDelegate
|
||||
|
||||
extension Workspace: BonsplitDelegate {
|
||||
@MainActor
|
||||
private func shouldCloseWorkspaceOnLastSurface(for tabId: TabID) -> Bool {
|
||||
let manager = owningTabManager ?? AppDelegate.shared?.tabManagerFor(tabId: id) ?? AppDelegate.shared?.tabManager
|
||||
guard LastSurfaceCloseShortcutSettings.closesWorkspace(),
|
||||
panels.count <= 1,
|
||||
panelIdFromSurfaceId(tabId) != nil,
|
||||
let manager,
|
||||
manager.tabs.contains(where: { $0.id == id }) else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func confirmClosePanel(for tabId: TabID) async -> Bool {
|
||||
let alert = NSAlert()
|
||||
|
|
@ -4529,6 +4543,12 @@ extension Workspace: BonsplitDelegate {
|
|||
return false
|
||||
}
|
||||
|
||||
if shouldCloseWorkspaceOnLastSurface(for: tab.id) {
|
||||
clearStagedClosedBrowserRestoreSnapshot(for: tab.id)
|
||||
owningTabManager?.closeWorkspaceWithConfirmation(self)
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the panel needs close confirmation
|
||||
guard let panelId = panelIdFromSurfaceId(tab.id),
|
||||
let terminalPanel = terminalPanel(for: panelId) else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue