Skip to content

fix: resolve Windows clipboard (Ctrl+V/X/C) not working in WebView2#517

Merged
j4rviscmd merged 4 commits into
mainfrom
fix/windows-paste-sendinput
May 10, 2026
Merged

fix: resolve Windows clipboard (Ctrl+V/X/C) not working in WebView2#517
j4rviscmd merged 4 commits into
mainfrom
fix/windows-paste-sendinput

Conversation

@j4rviscmd
Copy link
Copy Markdown
Owner

Summary

  • Fix Ctrl+V/X/C clipboard operations not working on Windows in Tauri/WebView2
  • Make native Tauri menu macOS-only to prevent keyboard accelerator interception on Windows/Linux
  • Add platform.isTauri to clipboard keybinding registration for Cut/Copy/Paste actions
  • Use direct clipboard read + synthetic paste event dispatch instead of SendInput-triggered re-entrancy

Changes

Root causes fixed

  1. Native menu interception: Tauri's predefined menu items (.paste(), .cut(), .copy()) registered keyboard accelerators that intercepted Ctrl+V/X/C before reaching the WebView. The paste handler called execCommand('paste') which WebView2 blocks for security.
  2. Missing keybindings: platform.isNative is false in Tauri, so PasteAction/CutAction/CopyAction had no Ctrl+V/X/C keybindings registered.
  3. Re-entrancy: SendInput-synthesized Ctrl+V was re-caught by the PasteAction keybinding, causing an infinite interception loop. Replaced with direct clipboard read + editor.trigger() for the editor and synthetic ClipboardEvent('paste') dispatch for non-editor contexts (terminal, etc.).

Files changed

  • src-tauri/src/commands/native_host/clipboard.rs — Replace PowerShell SendKeys with Win32 SendInput API, simplify helper methods
  • src-tauri/src/window/menu.rs — Make native menu setup macOS-only via #[cfg(target_os = "macos")]
  • src/vs/editor/contrib/clipboard/browser/clipboard.ts — Add platform.isTauri to kbOpts for Cut/Copy/Paste, add Tauri-specific paste paths (direct clipboard read for editor, synthetic paste event for terminal)
  • src/vs/workbench/services/clipboard/tauri-browser/clipboardService.ts — Disable triggerPaste() (return undefined) to use direct clipboard read path instead

Test plan

  • Ctrl+V paste in code editor (Windows)
  • Ctrl+C copy in code editor (Windows)
  • Ctrl+X cut in code editor (Windows)
  • Ctrl+V paste in integrated terminal (Windows)
  • Right-click paste still works
  • No error toast on Ctrl+V
  • Verify macOS clipboard still works (existing menu-based flow unaffected)

🤖 Generated with Claude Code

j4rviscmd and others added 2 commits May 11, 2026 00:11
Three root causes prevented clipboard operations on Windows:

1. Native Tauri menu registered keyboard accelerators for cut/copy/paste
   that intercepted keystrokes before reaching the WebView, and its
   paste handler called execCommand('paste') which WebView2 blocks
   for security → made menu macOS-only.

2. platform.isNative is false in Tauri, so PasteAction/CutAction/CopyAction
   had no Ctrl+V/X/C keybinding registered → added platform.isTauri
   to the kbOpts condition for all three actions.

3. SendInput-synthesized Ctrl+V was re-caught by PasteAction (re-entrancy)
   and triggerPaste via external process was fragile → disabled
   triggerPaste and use direct clipboard read + editor.trigger() for the
   editor, and synthetic ClipboardEvent dispatch for non-editor contexts
   (terminal, etc.).

Also replaced PowerShell SendKeys with Win32 SendInput API and
simplified clipboard helper methods.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@j4rviscmd j4rviscmd added bug Something isn't working tauri Tauri 2.0 移行関連 windows labels May 10, 2026
j4rviscmd and others added 2 commits May 11, 2026 00:21
CI failed because cargo fmt --check found formatting issues.
Ran cargo fmt to auto-format the code.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Clippy warned that `map_or(false, |t| !t.is_empty())` can be simplified to `is_ok_and(|t| !t.is_empty())`.

Resolves CI Backend Lint (Clippy) failure.
@j4rviscmd j4rviscmd merged commit 2a861cf into main May 10, 2026
7 checks passed
@j4rviscmd j4rviscmd deleted the fix/windows-paste-sendinput branch May 10, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working tauri Tauri 2.0 移行関連 windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant