Skip to content

Use native clipboard for terminal copy and paste#724

Open
Sebastefanelli wants to merge 3 commits into
crynta:mainfrom
Sebastefanelli:fix/terminal-native-clipboard
Open

Use native clipboard for terminal copy and paste#724
Sebastefanelli wants to merge 3 commits into
crynta:mainfrom
Sebastefanelli:fix/terminal-native-clipboard

Conversation

@Sebastefanelli

@Sebastefanelli Sebastefanelli commented Jun 4, 2026

Copy link
Copy Markdown

Fixes #713.

Summary

  • route terminal Ctrl+Shift+C and Ctrl+Shift+V through Tauri's native clipboard plugin
  • keep the existing web clipboard API as a fallback for browser/dev contexts
  • register clipboard-manager and grant read/write text permissions
  • add tests for native-first clipboard read/write behavior and web fallback

Validation

  • pnpm --config.verify-deps-before-run=false test
  • pnpm --config.verify-deps-before-run=false check-types
  • pnpm --config.verify-deps-before-run=false build
  • cargo check
  • cargo test
  • manually verified on Linux that text copied from another app pastes into the Terax terminal with Ctrl+Shift+V

Summary by CodeRabbit

  • New Features
    • Enabled native clipboard manager support and granted read/write clipboard permissions.
    • Added terminal clipboard integration that works with both native and web clipboard, including automatic fallback.
  • Bug Fixes
    • Improved terminal paste behavior to only apply clipboard contents when the active target is unchanged during async reads.
  • Tests
    • Added a test suite covering native-first clipboard reads/writes and web fallback when native access fails.

@Sebastefanelli Sebastefanelli force-pushed the fix/terminal-native-clipboard branch from 34886ec to 91d3a70 Compare June 4, 2026 19:31
Zarritas pushed a commit to Zarritas/terax-ai that referenced this pull request Jun 5, 2026
…rynta#724)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@davepuchyr

Copy link
Copy Markdown

The copy-paste functionality of this is crucial. Any chance it'll land in the next release?

@Sebastefanelli Sebastefanelli marked this pull request as ready for review June 20, 2026 00:33
@Sebastefanelli Sebastefanelli requested a review from crynta as a code owner June 20, 2026 00:33
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f5a19646-5df9-49d2-9b7c-80b5c648b85f

📥 Commits

Reviewing files that changed from the base of the PR and between 24c0be9 and a40dca2.

📒 Files selected for processing (1)
  • src/modules/terminal/lib/rendererPool.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/modules/terminal/lib/rendererPool.ts

📝 Walkthrough

Walkthrough

Adds the tauri-plugin-clipboard-manager plugin across the full stack (Cargo, npm, capabilities, Rust init), introduces a new terminalClipboard.ts utility that reads/writes via the Tauri native clipboard plugin with a navigator.clipboard fallback, and updates the xterm key handler in rendererPool.ts to use this abstraction instead of direct browser clipboard calls.

Changes

Terminal Clipboard via Tauri Plugin

Layer / File(s) Summary
Plugin registration, permissions, and JS dependency
package.json, src-tauri/Cargo.toml, src-tauri/capabilities/default.json, src-tauri/src/lib.rs
Registers the tauri-plugin-clipboard-manager crate and npm package, grants clipboard-manager:allow-read-text and clipboard-manager:allow-write-text capability permissions, and calls tauri_plugin_clipboard_manager::init() in the builder chain.
terminalClipboard utility and tests
src/modules/terminal/lib/terminalClipboard.ts, src/modules/terminal/lib/terminalClipboard.test.ts
Adds readTerminalClipboard and writeTerminalClipboard with Tauri-first, web-fallback strategy; getWebClipboard() guards safe access to navigator.clipboard. Tests cover native-success and native-failure (fallback) paths for both read and write.
rendererPool xterm key handler clipboard swap
src/modules/terminal/lib/rendererPool.ts
Imports readTerminalClipboard/writeTerminalClipboard and replaces the direct navigator.clipboard.writeText/readText calls in the Ctrl+Shift+C/V handler; adds a targetLeafId check to verify the leaf hasn't changed before applying pasted text.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • #713 — Ctrl+Shift+V fails for text copied outside Terax on Linux: This PR directly implements the confirmed fix described in that issue — switching terminal copy/paste from navigator.clipboard to @tauri-apps/plugin-clipboard-manager with web fallback, exactly targeting the WebKit clipboard boundary failure on Linux.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly and concisely describes the primary change (native clipboard for terminal operations) and follows Conventional Commits format.
Linked Issues check ✅ Passed PR fully addresses issue #713: routes terminal copy/paste through Tauri's native clipboard plugin with web fallback, adds tests, and confirms native-first behavior on Linux.
Out of Scope Changes check ✅ Passed All changes are scoped to terminal clipboard functionality: dependency additions, capability grants, plugin initialization, and clipboard abstraction layer with tests.

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


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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modules/terminal/lib/rendererPool.ts`:
- Around line 289-292: The asynchronous readTerminalClipboard call in the
keydown event handler can resolve after the renderer slot has been rebound to a
different terminal session due to pooling and tab switching. Capture a reference
to the current slot or leaf before initiating the readTerminalClipboard promise,
then in the promise resolution handler (the then callback where slot.term.paste
is called) verify that the same leaf is still bound to the slot. Only proceed
with the paste operation if the leaf binding has not changed, otherwise the text
will be pasted into the wrong terminal session.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ae6c7215-f0dc-4ff0-b0b7-1b48aab22c28

📥 Commits

Reviewing files that changed from the base of the PR and between 4b95be5 and 24c0be9.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/pnpm-lock.yaml
  • src-tauri/Cargo.lock is excluded by !**/*.lock, !**/*.lock, !src-tauri/Cargo.lock
📒 Files selected for processing (7)
  • package.json
  • src-tauri/Cargo.toml
  • src-tauri/capabilities/default.json
  • src-tauri/src/lib.rs
  • src/modules/terminal/lib/rendererPool.ts
  • src/modules/terminal/lib/terminalClipboard.test.ts
  • src/modules/terminal/lib/terminalClipboard.ts

Comment thread src/modules/terminal/lib/rendererPool.ts
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.

Ctrl+Shift+V fails for text copied outside Terax on Linux

2 participants