Repository navigation
webview: preserve text selection before clipboard commands - #344428
Merged
Merged
Conversation
Avoid restoring the last focused input when a non-collapsed document selection exists, so copying rendered webview text does not clear the selection. Preserve focus restoration for empty and collapsed selections. Fixes #343489 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
This PR will be automatically cherry-picked to |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow fix addresses selection loss, preserves existing focus safeguards, and includes targeted regression coverage with no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes the webview clipboard regression introduced by #341552 by preserving selected rendered text instead of refocusing a previously used input.
Changes:
- Skip focus restoration for non-collapsed document selections while retaining existing focus safeguards.
- Update the preload script’s Content Security Policy hash.
- Add Copy, Cut, and Paste regression coverage for body/document-element focus, plus collapsed-selection coverage.
| File | Description |
|---|---|
| src/vs/workbench/contrib/webview/test/node/webviewShellMessaging.test.ts | Tests selection preservation and retained focus restoration. |
| src/vs/workbench/contrib/webview/browser/pre/index.html | Guards focus restoration and updates the script hash. |
Review effort: Balanced
Dmitriy Vasyura (dmitrivMS)
marked this pull request as ready for review
October 26, 2026 21:35
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
October 26, 2026 21:36
Ross Wollman (rwoll)
approved these changes
Oct 26, 2026
Dmitriy Vasyura (dmitrivMS)
deleted the
agents/fix-vscode-issue-343489
branch
October 26, 2026 21:38
Supan Adit Pratama (supanadit)
added a commit
to supanadit/morse
that referenced
this pull request
Oct 31, 2026
VS Code 1.143 restores focus to the webview's last focused element right before running the clipboard command. When that element is the composer textarea, focusing it collapses a selection made in the transcript, so Ctrl+C and the context-menu Copy both copy nothing. Land plain pointer presses on the non-editable shell instead, so the webview's activeElement is not body and the restore is skipped. The guard only runs in a webview; the browser host keeps its focus behavior. Upstream fix is in VS Code 1.144 (microsoft/vscode#344428); this keeps 1.143 usable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.