Handle Cmd+O in handleCustomShortcut to prevent Documents folder open (#2034)
* Handle Cmd+O in handleCustomShortcut to prevent Documents folder open Cmd+O for "Open Folder" was only handled in SwiftUI menu, which can fail due to focus bugs when terminal is focused. This caused AppKit's default NSDocumentController to open the Documents folder instead. Now Cmd+O is intercepted in handleCustomShortcut like other shortcuts. Fixes #2010 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix fallback directory loss and deduplicate Open Folder logic Address review feedback: 1. Pass selected directory URL to fallback window creation so the user's folder choice is not silently discarded 2. Replace inline NSOpenPanel code in cmuxApp.swift menu action with a call to AppDelegate.showOpenFolderPanel() to avoid future divergence between the two code paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Set NSOpenPanel directoryURL to current terminal working directory Address review feedback: set panel.directoryURL to the focused terminal's working directory so Open Folder starts in a contextually relevant location instead of AppKit's default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Use shared main-window resolver and openWorkspaceForExternalDirectory in showOpenFolderPanel Address review feedback: use preferredMainWindowContextForWorkspaceCreation for directory seeding (works when auxiliary windows are key) and openWorkspaceForExternalDirectory for workspace creation (ensures shouldBringToFront and consistent fallback behavior). --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Lawrence Chen <lawrencecchen@users.noreply.github.com>
This commit is contained in:
parent
68ff39c444
commit
5b82041160
2 changed files with 33 additions and 18 deletions
|
|
@ -5385,6 +5385,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"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func openWindow(
|
||||
_ pasteboard: NSPasteboard,
|
||||
userData: String?,
|
||||
|
|
@ -9336,6 +9360,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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue