Repository navigation
fix(openFolder): set NSOpenPanel directoryURL to focused pane's working directory #2019
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
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5975,8 +5975,11 @@ struct ContentView: View { | |||||||||||||||||||||||||||||||||||
| panel.allowsMultipleSelection = false | ||||||||||||||||||||||||||||||||||||
| panel.title = String(localized: "panel.openFolder.title", defaultValue: "Open Folder") | ||||||||||||||||||||||||||||||||||||
| panel.prompt = String(localized: "panel.openFolder.prompt", defaultValue: "Open") | ||||||||||||||||||||||||||||||||||||
| if let preferredDir = self.tabManager.selectedWorkspace?.focusedPanelId.flatMap({ self.tabManager.selectedWorkspace?.panelDirectories[$0] }), !preferredDir.isEmpty { | ||||||||||||||||||||||||||||||||||||
| panel.directoryURL = URL(fileURLWithPath: preferredDir) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5978
to
+5980
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. Use workspace directory fallback before defaulting to NSOpenPanel’s default location. Line 5978 only uses the focused panel directory. When that value is absent, this still falls back to default picker behavior instead of the workspace directory context, so the issue can reproduce. 💡 Proposed fix- if let preferredDir = self.tabManager.selectedWorkspace?.focusedPanelId.flatMap({ self.tabManager.selectedWorkspace?.panelDirectories[$0] }), !preferredDir.isEmpty {
- panel.directoryURL = URL(fileURLWithPath: preferredDir)
- }
+ if let workspace = self.tabManager.selectedWorkspace {
+ let focusedDir = workspace.focusedPanelId
+ .flatMap { workspace.panelDirectories[$0] }?
+ .trimmingCharacters(in: .whitespacesAndNewlines)
+ let workspaceDir = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines)
+
+ if let focusedDir, !focusedDir.isEmpty, FileManager.default.fileExists(atPath: focusedDir) {
+ panel.directoryURL = URL(fileURLWithPath: focusedDir, isDirectory: true)
+ } else if !workspaceDir.isEmpty, FileManager.default.fileExists(atPath: workspaceDir) {
+ panel.directoryURL = URL(fileURLWithPath: workspaceDir, isDirectory: true)
+ } else {
+ panel.directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
+ }
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| if panel.runModal() == .OK, let url = panel.url { | ||||||||||||||||||||||||||||||||||||
| tabManager.addWorkspace(workingDirectory: url.path) | ||||||||||||||||||||||||||||||||||||
| self.tabManager.addWorkspace(workingDirectory: url.path) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -593,6 +593,9 @@ struct cmuxApp: App { | |
| panel.allowsMultipleSelection = false | ||
| panel.title = String(localized: "menu.file.openFolder.panelTitle", defaultValue: "Open Folder") | ||
| panel.prompt = String(localized: "menu.file.openFolder.panelPrompt", defaultValue: "Open") | ||
| if let preferredDir = self.activeTabManager.selectedWorkspace?.focusedPanelId.flatMap({ self.activeTabManager.selectedWorkspace?.panelDirectories[$0] }), !preferredDir.isEmpty { | ||
| panel.directoryURL = URL(fileURLWithPath: preferredDir) | ||
| } | ||
|
Comment on lines
+596
to
+598
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. Add workspace-level fallback before defaulting to Documents Line 596 only uses 💡 Suggested patch- if let preferredDir = self.activeTabManager.selectedWorkspace?.focusedPanelId.flatMap({ self.activeTabManager.selectedWorkspace?.panelDirectories[$0] }), !preferredDir.isEmpty {
- panel.directoryURL = URL(fileURLWithPath: preferredDir)
- }
+ let workspace = self.activeTabManager.selectedWorkspace
+ let focusedPaneDir = workspace.flatMap { ws in
+ ws.focusedPanelId.flatMap { ws.panelDirectories[$0] }
+ }
+ let startDir = (
+ focusedPaneDir
+ ?? workspace?.currentDirectory
+ ?? NSString(string: "~/Documents").expandingTildeInPath
+ ).trimmingCharacters(in: .whitespacesAndNewlines)
+ if !startDir.isEmpty {
+ panel.directoryURL = URL(fileURLWithPath: startDir)
+ }🤖 Prompt for AI Agents |
||
| if panel.runModal() == .OK, let url = panel.url { | ||
| if let appDelegate = AppDelegate.shared { | ||
| if appDelegate.addWorkspaceInPreferredMainWindow( | ||
|
|
@@ -602,7 +605,7 @@ struct cmuxApp: App { | |
| appDelegate.openNewMainWindow(nil) | ||
| } | ||
| } else { | ||
| activeTabManager.addWorkspace(workingDirectory: url.path) | ||
| self.activeTabManager.addWorkspace(workingDirectory: url.path) | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDirectory: truewhen constructing directory URLURL(fileURLWithPath:)withoutisDirectory: trueconsults the file system to infer whether the path is a file or directory. If the working directory stored inpanelDirectorieshas since been deleted (e.g. the userrm -rf'd a temp dir in the terminal), the stat will fail and the resulting URL will havehasDirectoryPath == false.NSOpenPanelignores adirectoryURLthat isn't a directory URL, silently falling back to~/Documents— the exact behavior this PR is trying to fix.Explicitly passing
isDirectory: truemakes the intent unambiguous and ensures the URL is formed correctly regardless of whether the path still exists on disk:The same issue exists in
Sources/cmuxApp.swift:597.