Skip to content

fix(vscode): bridge clipboard and forward keystrokes in webview - #970

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
rushelex:fix/vscode-keybinding-forward-969
Jun 26, 2026
Merged

backnotprop merged 1 commit into
backnotprop:mainfrom
rushelex:fix/vscode-keybinding-forward-969

Conversation

@rushelex

Copy link
Copy Markdown
Contributor

Closes #864. Closes #969.

The Plannotator app runs inside a nested cross-origin iframe within the VS
Code webview. Two separate input paths break there, both rooted in the same
constraint — the inner document never holds focus and events don't cross the
iframe boundary:

Symptom Issue
Copy / cut / paste silently fail (keyboard and app buttons) #864
VS Code keybindings (Cmd+P, Cmd+Shift+P, …) dead while a Plannotator tab is focused #969

Root cause

The one input signal the iframe still receives is keydown. Both fixes hang off it.

Fix

  • Clipboard bridge: route reads/writes through the extension host, which
    owns the system clipboard via vscode.env.clipboard. The injected script
    overrides navigator.clipboard (for app buttons) and handles Cmd+C/X/V on
    keydown (for native shortcuts), relaying through the wrapper to an
    onDidReceiveMessage handler and back.
  • Keystroke forwarding: all other keys are posted to the wrapper, which
    re-dispatches a synthetic KeyboardEvent on the webview document so VS Code
    can resolve its shortcuts. Undo/redo/select-all stay native.

Testing

  • bun test apps/vscode-extension/src/ → 23 pass.
  • bun run build:vscode succeeds; tsc clean.
  • Manually verified in VS Code (1.125.1): Cmd+C / Cmd+V / Cmd+X, app copy
    buttons, and Cmd+P all work in a focused Plannotator tab.

🤖 Generated with Claude Code

The Plannotator app runs in a nested cross-origin iframe inside the VS Code
webview, where two input paths break:

- Clipboard: the iframe document never holds focus, so the async Clipboard
  API is rejected ("Document is not focused") and native copy/cut/paste
  events never fire. Copy, cut, and paste all silently fail.
- Keybindings: keydown events don't cross the iframe boundary, so VS Code
  never sees global shortcuts (Cmd+P, etc.) while a Plannotator tab is focused.

Fix both off the one input signal the iframe still receives — keydown:

- Route clipboard reads/writes through the extension host, which owns the
  system clipboard via vscode.env.clipboard. The injected script overrides
  navigator.clipboard and handles Cmd+C/X/V, relaying through the wrapper to
  an onDidReceiveMessage handler and back.
- Forward all other keystrokes to the wrapper, which re-dispatches a synthetic
  KeyboardEvent on the webview document so VS Code can resolve its keybindings.
  Undo/redo/select-all stay native.

Fixes backnotprop#864
Fixes backnotprop#969

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@backnotprop

Copy link
Copy Markdown
Owner

thanks!

@backnotprop
backnotprop merged commit 1e631ac into backnotprop:main Jun 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants