Skip to content

fix: use native Tauri clipboard plugin on all platforms (fixes terminal copy/paste on Windows)#923

Open
baoyu0 wants to merge 1 commit into
crynta:mainfrom
baoyu0:fix/terminal-clipboard-windows
Open

fix: use native Tauri clipboard plugin on all platforms (fixes terminal copy/paste on Windows)#923
baoyu0 wants to merge 1 commit into
crynta:mainfrom
baoyu0:fix/terminal-clipboard-windows

Conversation

@baoyu0

@baoyu0 baoyu0 commented Jul 2, 2026

Copy link
Copy Markdown

Problem

The terminal clipboard functions (writeTerminalClipboard, readTerminalClipboard, writeSystemClipboard) only used the native @tauri-apps/plugin-clipboard-manager on Linux via an IS_LINUX guard. On Windows and macOS they fell back to navigator.clipboard.writeText(), which silently fails in Tauri's WebView2 renderer (and macOS WKWebView), making:

  • Ctrl+Shift+C / Ctrl+Shift+V keyboard copy/paste
  • OSC 52 clipboard operations (SSH remote clipboard)
  • Right-click context menu copy (in some configurations)

all non-functional on Windows.

The .catch(() => {}) in the existing code swallows the error, so users see no feedback — the copy/paste just silently does nothing.

Root Cause

terminalClipboard.ts had exclusive Linux guard:

if (IS_LINUX) {
  // try native plugin
}
// fallback: navigator.clipboard (fails in WebView2 on Windows)

osc-handlers.ts had no native plugin path at all — it always called navigator.clipboard.writeText() directly.

Fix

  1. src/modules/terminal/lib/terminalClipboard.ts — Remove the IS_LINUX guard. Try the native @tauri-apps/plugin-clipboard-manager on every platform first, with navigator.clipboard as a last-resort fallback for non-Tauri environments (e.g. unit tests, dev in plain browser).

  2. src/modules/terminal/lib/osc-handlers.ts — Update writeSystemClipboard to use the native plugin with the same try/catch pattern.

The @tauri-apps/plugin-clipboard-manager is already a dependency in package.json — no new dependencies needed.

Related Issues

Summary by CodeRabbit

  • Bug Fixes
    • Improved clipboard reliability by trying the app’s native clipboard integration first, with a browser-based fallback if needed.
    • Made clipboard reading and writing work more consistently across platforms.
    • Enhanced terminal clipboard parsing to better handle encoded content and file path detection.

The terminal clipboard functions (`writeTerminalClipboard`,
`readTerminalClipboard`, `writeSystemClipboard`) only used the native
`@tauri-apps/plugin-clipboard-manager` on Linux via an `IS_LINUX` guard.
On Windows and macOS they fell back to `navigator.clipboard.writeText()`,
which silently fails in Tauri's WebView2 renderer, making Ctrl+Shift+C/V
and OSC 52 clipboard operations non-functional.

- Remove the `IS_LINUX` guard from `terminalClipboard.ts` so the native
  plugin is tried on every platform first, with `navigator.clipboard` as
  fallback.
- Update `writeSystemClipboard` in `osc-handlers.ts` to use the native
  plugin with the same pattern.
@baoyu0 baoyu0 requested a review from crynta as a code owner July 2, 2026 07:18
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

OSC7 CWD path parsing uses a revised file:// regex, OSC52 clipboard payload strips whitespace before base64 validation, and clipboard read/write functions across osc-handlers.ts and terminalClipboard.ts now prefer the Tauri clipboard-manager plugin (dynamic import) before falling back to navigator.clipboard, removing prior Linux-only gating.

Changes

Clipboard and OSC parsing fixes

Layer / File(s) Summary
OSC7/OSC52 parsing and system clipboard write
src/modules/terminal/lib/osc-handlers.ts
parseOsc7 uses a revised `file://` regex to extract the CWD path, parseOsc52Clipboard strips whitespace before base64 validation, and writeSystemClipboard tries the Tauri clipboard plugin via dynamic import before falling back to `navigator.clipboard.writeText`.
Terminal clipboard read/write via Tauri plugin
src/modules/terminal/lib/terminalClipboard.ts
readTerminalClipboard and writeTerminalClipboard drop the Linux-only gating and unconditionally try the Tauri clipboard plugin first, falling back to `navigator.clipboard` on failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • crynta/terax-ai#821: Same OSC52 base64 normalization and `writeSystemClipboard` Tauri-first logic in `osc-handlers.ts`.
  • crynta/terax-ai#895: Same Tauri-first/navigator-fallback rework of `readTerminalClipboard`/`writeTerminalClipboard` in `terminalClipboard.ts`.

Poem:

A rabbit hopped past WebView2's wall,
where clipboard signals used to stall.
Now Tauri's plugin leads the way,
navigator waits, just in case, to save the day.
Ctrl+C, Ctrl+V, copy and paste — hooray! 🐇📋


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.

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

Labels

None yet

Projects

None yet

1 participant