Fix Cmd+W close flow to confirm unsaved editor tabs

This commit is contained in:
h3p 2026-03-08 13:20:14 +01:00
parent 36a453c232
commit 62b0d70189
5 changed files with 12 additions and 7 deletions

View file

@ -361,7 +361,7 @@
CODE_SIGNING_ALLOWED = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 429;
CURRENT_PROJECT_VERSION = 430;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = CS727NF72U;
ENABLE_APP_SANDBOX = YES;
@ -444,7 +444,7 @@
CODE_SIGNING_ALLOWED = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 429;
CURRENT_PROJECT_VERSION = 430;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = CS727NF72U;
ENABLE_APP_SANDBOX = YES;

View file

@ -6,6 +6,7 @@ import FoundationModels
struct NeonVisionMacAppCommands: Commands {
let activeEditorViewModel: () -> EditorViewModel
let hasActiveEditorWindow: () -> Bool
let openNewWindow: () -> Void
let openAIDiagnosticsWindow: () -> Void
let postWindowCommand: (_ name: Notification.Name, _ object: Any?) -> Void
@ -121,13 +122,10 @@ struct NeonVisionMacAppCommands: Commands {
Divider()
Button("Close Tab") {
let current = activeEditorViewModel()
if let tab = current.selectedTab {
current.closeTab(tabID: tab.id)
}
post(.closeSelectedTabRequested)
}
.keyboardShortcut("w", modifiers: .command)
.disabled(!hasSelectedTab)
.disabled(!hasActiveEditorWindow() || !hasSelectedTab)
}
}

View file

@ -368,6 +368,7 @@ struct NeonVisionEditorApp: App {
.commands {
NeonVisionMacAppCommands(
activeEditorViewModel: { activeEditorViewModel },
hasActiveEditorWindow: { WindowViewModelRegistry.shared.activeViewModel() != nil },
openNewWindow: { openWindow(id: "blank-window") },
openAIDiagnosticsWindow: { openWindow(id: "ai-logs") },
postWindowCommand: { name, object in

View file

@ -1612,6 +1612,11 @@ struct ContentView: View {
openSettings()
}
}
.onReceive(NotificationCenter.default.publisher(for: .closeSelectedTabRequested)) { notif in
guard matchesCurrentWindow(notif) else { return }
guard let tab = viewModel.selectedTab else { return }
requestCloseTab(tab)
}
.onReceive(NotificationCenter.default.publisher(for: .showUpdaterRequested)) { notif in
guard matchesCurrentWindow(notif) else { return }
let shouldCheckNow = (notif.object as? Bool) ?? true

View file

@ -777,6 +777,7 @@ extension Notification.Name {
static let keyboardAccessoryBarVisibilityChanged = Notification.Name("keyboardAccessoryBarVisibilityChanged")
static let showUpdaterRequested = Notification.Name("showUpdaterRequested")
static let showSettingsRequested = Notification.Name("showSettingsRequested")
static let closeSelectedTabRequested = Notification.Name("closeSelectedTabRequested")
}
extension NSRange {