Skip to content

[cherry-pick] webview: preserve text selection before clipboard commands - #344437

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
release/1.144from
cherry-pick/344428
Oct 26, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 1 commit into
release/1.144from
cherry-pick/344428

Conversation

@vs-code-engineering

Copy link
Copy Markdown
Contributor

Cherry-pick of #344428 from main.

Fixes #343489.

The focus restoration introduced by #341552 can refocus a previously used textarea before Copy runs, clearing a selection in non-focusable rendered webview content.

  • Skip focus restoration while a non-collapsed document selection exists; retain restoration for empty or collapsed selections.
  • Update the preload script CSP hash.
  • Add regression coverage for Copy, Cut, and Paste with body/document-element focus, and preserve existing input-focus behavior.

Copilot AI balanced review requested due to automatic review settings October 26, 2026 21:40
@vs-code-engineering vs-code-engineering Bot added the cherry-pick-artifact Auto-generated cherry-pick PR label Oct 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrow fix preserves existing focus behavior, has targeted regression coverage and a verified CSP hash, and has no unresolved findings.

No open issues 🎉

What changed in this PR

This cherry-pick fixes webview clipboard commands clearing selected text by refocusing a previously used input, addressing #343489.

Changes:

  • Preserve non-collapsed document selections while retaining focus restoration for empty or collapsed selections.
  • Update the preload script’s CSP hash.
  • Add regression coverage for Copy, Cut, and Paste with body or document-element focus.
File Description
src/​vs/​workbench/​contrib/​webview/​test/​node/​webviewShellMessaging.test.ts Tests selection preservation and collapsed-selection focus restoration.
src/​vs/​workbench/​contrib/​webview/​browser/​pre/​index.html Guards focus restoration when text is selected and updates the CSP hash.

Review effort: Balanced

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the webview Webview issues label Oct 26, 2026
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit da539df into release/1.144 Oct 26, 2026
45 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the cherry-pick/344428 branch October 26, 2026 21:58
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-artifact Auto-generated cherry-pick PR webview Webview issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants