Repository navigation
Handle Cmd+O in handleCustomShortcut to prevent Documents folder open #2034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2d4ffcb
553d35c
d3538d4
43d8469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5363,6 +5363,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent | |
| _ = createMainWindow() | ||
| } | ||
|
|
||
| /// Shows the "Open Folder" panel and creates a workspace for the selected directory. | ||
| /// Called from both the SwiftUI menu and `handleCustomShortcut`. | ||
| func showOpenFolderPanel() { | ||
| let panel = NSOpenPanel() | ||
| panel.canChooseFiles = false | ||
| panel.canChooseDirectories = true | ||
| panel.allowsMultipleSelection = false | ||
| panel.title = String(localized: "menu.file.openFolder.panelTitle", defaultValue: "Open Folder") | ||
| panel.prompt = String(localized: "menu.file.openFolder.panelPrompt", defaultValue: "Open") | ||
| // Seed the panel with the active workspace's directory. Use the shared | ||
| // main-window resolver so this works even when an auxiliary window is key. | ||
| if let context = preferredMainWindowContextForWorkspaceCreation(debugSource: "openFolderPanel.seed"), | ||
| let cwd = context.tabManager.selectedWorkspace?.currentDirectory, | ||
| !cwd.isEmpty { | ||
| panel.directoryURL = URL(fileURLWithPath: cwd) | ||
| } | ||
| if panel.runModal() == .OK, let url = panel.url { | ||
| openWorkspaceForExternalDirectory( | ||
| workingDirectory: url.path, | ||
| debugSource: "shortcut.openFolder" | ||
| ) | ||
|
Comment on lines
+5382
to
+5386
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mark confirmed folder picks as explicit startup opens. If this runs before the initial session-restore attempt and there is no main window yet, 💡 Suggested fix if panel.runModal() == .OK, let url = panel.url {
+ prepareForExplicitOpenIntentAtStartup()
openWorkspaceForExternalDirectory(
workingDirectory: url.path,
debugSource: "shortcut.openFolder"
)
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
Comment on lines
+5366
to
+5388
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The doc comment says "Extracted so it can be called from both the SwiftUI menu and This means there are now two divergent code paths for the same action:
A future change to panel titles, localization keys, or the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| @objc func openWindow( | ||
| _ pasteboard: NSPasteboard, | ||
| userData: String?, | ||
|
|
@@ -9309,6 +9333,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent | |
| return true | ||
| } | ||
|
|
||
| // Open Folder: Cmd+O | ||
| // Handled here to prevent AppKit's default NSDocumentController from opening | ||
| // the Documents folder when SwiftUI menu dispatch fails due to focus bugs. | ||
| if matchShortcut(event: event, shortcut: KeyboardShortcutSettings.shortcut(for: .openFolder)) { | ||
| showOpenFolderPanel() | ||
| return true | ||
| } | ||
|
|
||
| // Check Show Notifications shortcut | ||
| if matchShortcut(event: event, shortcut: KeyboardShortcutSettings.shortcut(for: .showNotifications)) { | ||
| toggleNotificationsPopover(animated: false, anchorView: fullscreenControlsViewModel?.notificationsAnchorView) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.