Skip to content

fix(openFolder): set NSOpenPanel directoryURL to focused pane's working directory - #2039

Closed
BillionClaw wants to merge 1 commit into
manaflow-ai:mainfrom
BillionClaw:fix/openfolder-directory-url
Closed

BillionClaw wants to merge 1 commit into
manaflow-ai:mainfrom
BillionClaw:fix/openfolder-directory-url

Conversation

@BillionClaw

@BillionClaw BillionClaw commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • What changed? Set the directoryURL property on NSOpenPanel before presenting it for the ⌘O Open Folder action, so the file picker opens at the selected workspace's working directory instead of the macOS default ~/Documents.

  • Why? NSOpenPanel defaults to ~/Documents when directoryURL is not set. By reading activeTabManager.selectedWorkspace?.currentDirectory (or tabManager.selectedWorkspace?.currentDirectory in the command palette path), the panel now opens at a contextually relevant location.

Testing

  • How did you test this change? Code review + verified the two NSOpenPanel call sites now set directoryURL from the workspace's current directory before calling runModal().
  • What did you verify manually? Confirmed currentDirectory is populated from the focused pane's shell integration and used as the fallback when set.

Files changed

  • Sources/cmuxApp.swift: menu File → Open Folder (⌘O) path
  • Sources/ContentView.swift: command palette palette.openFolder path

Review Trigger

@codex review
@coderabbitai review
@greptile-apps review
@cubic-dev-ai review

Summary by cubic

Open Folder now starts in the focused workspace’s working directory instead of ~/Documents. We set NSOpenPanel.directoryURL from the selected workspace’s currentDirectory in both the File → Open Folder (⌘O) and command palette actions.

Written for commit 27beb34. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • File → Open Folder dialog now opens to the current workspace directory, improving navigation efficiency and preserving workspace context.

@vercel

vercel Bot commented Mar 24, 2026

Copy link
Copy Markdown

@BillionClaw is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@coderabbitai

coderabbitai Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca6db3e6-e612-4e27-8486-a620c2edf49d

📥 Commits

Reviewing files that changed from the base of the PR and between 22c50a4 and 27beb34.

📒 Files selected for processing (2)
  • Sources/ContentView.swift
  • Sources/cmuxApp.swift

📝 Walkthrough

Walkthrough

The PR adds conditional preset directory configuration to folder selection dialogs in two files. When opening a folder via the palette or file menu, the NSOpenPanel now sets its starting directory to the currently selected workspace's stored directory path if available, enhancing navigation convenience.

Changes

Cohort / File(s) Summary
Folder Dialog Directory Preselection
Sources/ContentView.swift, Sources/cmuxApp.swift
Both files now conditionally set panel.directoryURL from the active workspace's currentDirectory before presenting the NSOpenPanel, allowing the file picker to open at the workspace's last known location.

Possibly related PRs

  • #656: Modifies the same palette.openFolder command handler and NSOpenPanel configuration.
  • #685: Modifies ContentView's folder-opening logic and related directory handling helpers.

Poem

🐰 A warren of folders, once lost in the mist,
Now greets workspace paths with a welcoming twist!
The panel remembers where last we did roam,
And whisks us back to our data-filled home! ✨

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: setting NSOpenPanel's directoryURL to the focused workspace's working directory.
Description check ✅ Passed The PR description covers all required template sections including summary of what changed and why, testing methodology and verification, files changed, and review triggers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the NSOpenPanel initial directory for the Open Folder action (⌘O and command palette) by setting directoryURL to the focused workspace's currentDirectory before calling runModal(). Without this, macOS defaulted to ~/Documents regardless of the terminal's working directory.

  • Sources/cmuxApp.swift: Before presenting NSOpenPanel in the menu File → Open Folder path, reads activeTabManager.selectedWorkspace?.currentDirectory and assigns it to panel.directoryURL when non-nil and non-empty.
  • Sources/ContentView.swift: Same fix applied to the command-palette palette.openFolder handler using tabManager.selectedWorkspace?.currentDirectory.
  • Both sites correctly guard against a nil workspace and an empty string, using URL(fileURLWithPath:) which is the standard way to construct a file:// URL accepted by NSOpenPanel.directoryURL.
  • If the workspace has no recorded working directory (e.g. shell integration not active), the panel falls back to the macOS default — the pre-existing behavior is preserved.

Confidence Score: 5/5

  • Safe to merge — a minimal, focused fix with no side effects.
  • The change is three lines at each of two call sites, the guard logic is correct (nil-check + empty-check), URL(fileURLWithPath:) is the idiomatic API for this purpose, and the fallback behavior (macOS default) is preserved when no cwd is available. No new strings, no threading changes, no behavioural regressions possible.
  • No files require special attention.

Important Files Changed

Filename Overview
Sources/ContentView.swift Adds directoryURL pre-seeding to NSOpenPanel in the command-palette palette.openFolder handler using tabManager.selectedWorkspace?.currentDirectory; guard for nil and empty string is correct, and the call sits inside the existing DispatchQueue.main.async block.
Sources/cmuxApp.swift Adds directoryURL pre-seeding to NSOpenPanel in the menu File → Open Folder (⌘O) path using activeTabManager.selectedWorkspace?.currentDirectory; pattern mirrors the ContentView change and is correctly guarded.

Sequence Diagram

sequenceDiagram
    participant User
    participant MenuOrPalette as Menu / Command Palette
    participant TabManager as TabManager
    participant Workspace as selectedWorkspace
    participant NSOpenPanel

    User->>MenuOrPalette: ⌘O / palette.openFolder
    MenuOrPalette->>TabManager: selectedWorkspace?.currentDirectory
    TabManager->>Workspace: currentDirectory (shell integration)
    Workspace-->>MenuOrPalette: "/path/to/cwd" (or nil/empty)
    MenuOrPalette->>NSOpenPanel: Create panel (canChooseDirectories=true)
    alt cwd is non-nil and non-empty
        MenuOrPalette->>NSOpenPanel: directoryURL = URL(fileURLWithPath: cwd)
    else cwd absent
        Note over NSOpenPanel: Falls back to ~/Documents (macOS default)
    end
    NSOpenPanel-->>User: Present file picker at cwd
    User->>NSOpenPanel: Select folder
    NSOpenPanel->>TabManager: addWorkspace(workingDirectory: url.path)
Loading

Reviews (1): Last reviewed commit: "fix(openFolder): set NSOpenPanel directo..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@lawrencecchen

Copy link
Copy Markdown
Contributor

Thanks for the contribution! This has been addressed by #2034 which was just merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants