Skip to content

Fix Monaco clipboard handling in webviews - #465

Open
Codeneos wants to merge 2 commits into
mainfrom
codex/monaco-clipboard-direct-paste
Open

Fix Monaco clipboard handling in webviews#465
Codeneos wants to merge 2 commits into
mainfrom
codex/monaco-clipboard-direct-paste

Conversation

@Codeneos

Copy link
Copy Markdown
Owner

Summary

  • Replace async keydown clipboard interception with explicit Monaco copy/cut/paste commands
  • Paste clipboard text via direct Monaco edits instead of routing through Monaco's native paste contribution

Validation

  • corepack pnpm exec eslint packages/vscode-webviews/src/shared/components/monaco-editor/monaco-editor.component.ts --no-error-on-unmatched-pattern
  • corepack pnpm run --filter @vlocode/vscode-webviews build

Copilot AI review requested due to automatic review settings June 30, 2026 18:26

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 554b81a3bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

editor.trigger('keyboard', 'paste', { text });
const selections = editor.getSelections() ?? [];
editor.pushUndoStop();
editor.executeEdits('clipboard', selections.map(selection => ({ range: selection, text })));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve multi-cursor paste distribution

When the clipboard was produced from multiple selections, copySelection serializes those selections as newline-separated text; with multiple cursors active, this direct edit now inserts the entire clipboard text at every cursor. Monaco's paste path previously handled the common multiCursorPaste: 'spread' case by distributing matching clipboard lines across cursors, so copying foo/bar from two cursors and pasting into two cursors now yields foo\nbar twice instead of foo and bar separately.

Useful? React with 👍 / 👎.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Replace editor.addCommand with per-editor onKeyDown interception. addCommand
registers unscoped keybindings on the singleton standalone keybinding service,
so with multiple Monaco editors mounted (formula list, preview input/output)
Ctrl+C/X/V targeted the last-created editor regardless of focus and leaked on
destroy. onKeyDown is scoped to the focused editor and disposed with it.

Restore editor.trigger('keyboard','paste',{text}) so paste keeps multi-cursor
spread and paste-on-new-line. Make the clipboard write fire-and-forget: the
host bridge is only required for read (paste) in a webview, so writes no longer
round-trip for an unused ack.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

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.

2 participants