Skip to content

fix(menu): restore paste in macOS native dialogs - #12645

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
pstanton237:macos-native-dialog-paste
Aug 6, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
pstanton237:macos-native-dialog-paste

Conversation

@pstanton237

@pstanton237 pstanton237 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • preserve Orca coordinated paste when a BrowserWindow is focused
  • forward Edit > Paste to the native macOS first responder when no BrowserWindow is focused
  • keep Windows and Linux behavior unchanged

The custom Edit > Paste handler replaced the Electron paste role so terminal and native-chat surfaces could coordinate clipboard ownership. When a native macOS open/save panel owned focus, BrowserWindow.getFocusedWindow() returned null and the handler became a no-op.

Screenshots

Before the fix, Cmd+V does not insert the clipboard path into the macOS Go to Folder field, while context-menu Paste remains available:

macOS Go to Folder field where keyboard paste fails

Testing

  • pnpm lint
  • pnpm typecheck
  • focused menu tests: 17 passed with one platform-specific skip
  • pnpm build under Node 24
  • added regression tests covering exact-once renderer routing, the macOS native responder fallback, and unchanged Linux/Windows behavior

The new macOS regression test fails against upstream main and passes on this branch.

AI Review Report

The AI coding-agent review and CodeRabbit checked exact-once routing, Electron focus behavior, and platform boundaries. No actionable code issues were found.

  • macOS: a focused Orca BrowserWindow still receives exactly one ui:appMenuPaste; only the no-focused-window path calls Menu.sendActionToFirstResponder("paste:")
  • Linux and Windows: the native responder fallback is not invoked, and the existing CmdOrCtrl+V accelerator remains unchanged
  • shortcuts, labels, file paths, shell behavior, SSH sessions, and folder workspaces are otherwise untouched

Security Audit

  • no new dependencies, authentication, secret handling, filesystem access, path parsing, or command execution
  • no new IPC channel; the focused-window path retains the existing ui:appMenuPaste message
  • the native fallback does not read clipboard contents and delegates only the standard paste: selector to the macOS first responder
  • the fallback is runtime-gated to macOS and only runs when no Orca BrowserWindow is focused, preventing double routing

Notes

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9074f2eb-1975-4d73-bbe4-2607fc456b99

📥 Commits

Reviewing files that changed from the base of the PR and between f4cf477 and a27a5b6.

📒 Files selected for processing (2)
  • src/main/menu/register-app-menu.test.ts
  • src/main/menu/register-app-menu.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/menu/register-app-menu.test.ts
  • src/main/menu/register-app-menu.ts

📝 Walkthrough

Walkthrough

The paste menu handler sends ui:appMenuPaste when a focused window exists. Without a focused window, macOS invokes Menu.sendActionToFirstResponder('paste:'). Linux and Windows do not invoke the native responder action. Tests mock the Electron API, reset mocks, restore spies, and cover each routing case.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes restoring paste behavior in macOS native dialogs.
Description check ✅ Passed The description covers the change, screenshot, testing, AI review, security audit, and platform-specific notes.
Linked Issues check ✅ Passed The implementation satisfies issue #12640 by preserving renderer paste and using the macOS first-responder fallback for native dialogs.
Out of Scope Changes check ✅ Passed The changes are limited to paste routing, platform-specific fallback behavior, and related regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

CI runs unit shards on ubuntu-latest only, so the unpinned paste-routing
test asserted "no native paste" vacuously: a double-route regression
passed green on Linux. Cover darwin/linux/win32 explicitly so the
exactly-once contract holds on every platform, and assert the item exists
in the negative-only cases so a rename cannot pass them silently.

Also document why the native first-responder fallback exists.

@Jinwoo-H Jinwoo-H left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks — the diagnosis is exactly right: the custom handler owns the CmdOrCtrl+V accelerator, so once getFocusedWindow() returned null the keystroke had nowhere to go.

Verified end-to-end in a real Electron run. Worth recording for anyone who revisits this: our folder pickers are parented (dialog.showOpenDialog(mainWindow, …) in src/main/ipc/repos.ts), so the panel is a window-modal sheet rather than a separate window. getFocusedWindow() still returns null there, the native branch fires, and the clipboard text lands in Go to Folder — while a pre-fix build in the same harness drops it. That was the one assumption the fix rested on that wasn't yet proven.

Two changes pushed on top:

  • The paste-routing test didn't pin process.platform. We run unit shards on ubuntu-latest only, so the "exactly one ui:appMenuPaste, no native paste" assertion passed vacuously — I confirmed by mutation that a double-paste regression ships green on a Linux runner. It's now it.each(['darwin','linux','win32']), which also keeps Linux/Windows coverage of the primary path (pinning to darwin alone would have removed it).
  • A // Why: on the native branch, plus expect(pasteItem).toBeDefined() in the negative-only cases so a rename can't pass them silently.

Kept the isMac guard exactly as you wrote it — worth noting it's load-bearing beyond platform parity: sendActionToFirstResponder is assigned unconditionally in Electron but only bound on macOS, and its type declaration is unconditional, so TypeScript wouldn't catch its removal.

The approach also matches what Electron's own role: 'paste' does internally, and mirrors the fallback the renderer already had (src/main/ipc/ui.ts → webContents.paste() when no Orca surface claims the paste) — the menu layer was the only link in that chain with a dead end instead of a delegation.

@Jinwoo-H
Jinwoo-H merged commit ca187c7 into stablyai:main Aug 6, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(menu): restore paste in macOS native dialogs

* test(menu): pin platform for paste routing coverage

CI runs unit shards on ubuntu-latest only, so the unpinned paste-routing
test asserted "no native paste" vacuously: a double-route regression
passed green on Linux. Cover darwin/linux/win32 explicitly so the
exactly-once contract holds on every platform, and assert the item exists
in the negative-only cases so a rename cannot pass them silently.

Also document why the native first-responder fallback exists.

---------

Co-authored-by: Jinwoo-H <[email protected]>
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.

[Bug]: Cmd+V does not paste into macOS native open/save dialogs

2 participants