Repository navigation
fix(openFolder): default NSOpenPanel to focused workspace directory #2070
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 |
|---|---|---|
|
|
@@ -5976,6 +5976,9 @@ 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 currentDir = tabManager.selectedTab?.currentDirectory { | ||
| panel.directoryURL = URL(fileURLWithPath: currentDir) | ||
|
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. P2: Open-folder panel start directory is derived from an unvalidated path, so empty/invalid values can open the picker in an unexpected location. Prompt for AI agents |
||
| } | ||
|
Comment on lines
+5979
to
+5981
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 focused directory + validate path before assigning Line 5979 currently uses Suggested fix- if let currentDir = tabManager.selectedTab?.currentDirectory {
- panel.directoryURL = URL(fileURLWithPath: currentDir)
- }
+ if let directory = focusedDirectory {
+ let trimmed = directory.trimmingCharacters(in: .whitespacesAndNewlines)
+ var isDirectory: ObjCBool = false
+ if !trimmed.isEmpty,
+ FileManager.default.fileExists(atPath: trimmed, isDirectory: &isDirectory),
+ isDirectory.boolValue {
+ panel.directoryURL = URL(fileURLWithPath: trimmed, isDirectory: true)
+ }
+ }🤖 Prompt for AI Agents |
||
| if panel.runModal() == .OK, let url = panel.url { | ||
| 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 currentDir = activeTabManager.selectedTab?.currentDirectory { | ||||||
| panel.directoryURL = URL(fileURLWithPath: currentDir) | ||||||
|
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.
Same note as
Suggested change
|
||||||
| } | ||||||
|
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. Validate On Line 597, Suggested fix- if let currentDir = activeTabManager.selectedTab?.currentDirectory {
- panel.directoryURL = URL(fileURLWithPath: currentDir)
- }
+ if let currentDir = activeTabManager.selectedTab?.currentDirectory?
+ .trimmingCharacters(in: .whitespacesAndNewlines),
+ !currentDir.isEmpty {
+ let candidateURL = URL(fileURLWithPath: currentDir).standardizedFileURL
+ var isDirectory: ObjCBool = false
+ if FileManager.default.fileExists(atPath: candidateURL.path, isDirectory: &isDirectory),
+ isDirectory.boolValue {
+ panel.directoryURL = candidateURL
+ }
+ }Based on learnings from 🤖 Prompt for AI Agents |
||||||
| if panel.runModal() == .OK, let url = panel.url { | ||||||
| if let appDelegate = AppDelegate.shared { | ||||||
| if appDelegate.addWorkspaceInPreferredMainWindow( | ||||||
|
|
||||||
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: truefor directory URLsURL(fileURLWithPath:)without anisDirectoryargument will inspect the filesystem (or fall back to a heuristic based on the trailing slash) to decide whether to treat the path as a directory. SincecurrentDirectoryis always a directory path, passisDirectory: trueexplicitly to guarantee a well-formed directory URL is handed toNSOpenPanel.