Fix blank lines when copying multiple empty selections#324294
Fix blank lines when copying multiple empty selections#324294CHENJIAMIAN wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #324290, where copying multiple empty selections (with emptySelectionClipboard enabled) and pasting into a single cursor introduced blank lines. The regression originated from commit 20e65fd2, which made getPlainTextToCopy append trailing line endings to whole-line (empty-selection) array entries. The clipboard plain-text payload in getDataToCopy then joined those already-terminated entries with an additional newline, producing blank lines. The PR keeps multicursorText intact for multi-cursor paste distribution and rebuilds the plain-text payload, plus adds a regression test.
Changes:
- Changed the plain-text payload construction in
getDataToCopyfromsourceText.join(newLineCharacter)tosourceText.join('')and removed the now-unusednewLineCharacterlocal. - Added a regression test in
cursor.test.tsfor copying three empty selections and pasting into a single cursor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/vs/editor/browser/controller/editContext/clipboardUtils.ts |
Rebuilds the clipboard plain-text payload by concatenating entries directly instead of joining with the EOL. This fixes the all-empty case but merges non-empty/mixed selections onto one line (regression flagged). |
src/vs/editor/test/browser/controller/cursor.test.ts |
Adds a regression test covering only the all-empty-selection scenario; does not cover the non-empty/mixed cases affected by the change. |
| const isFromEmptySelection = (emptySelectionClipboard && modelSelections.length === 1 && modelSelections[0].isEmpty()); | ||
| const multicursorText = (Array.isArray(sourceText) ? sourceText : null); | ||
| const text = (Array.isArray(sourceText) ? sourceText.join(newLineCharacter) : sourceText); | ||
| const text = (Array.isArray(sourceText) ? sourceText.join('') : sourceText); |
|
@microsoft-github-policy-service agree |
|
Updated this PR to handle mixed selections as well. What changed:
This keeps the |
Fixes #324290.
Summary
When copying from multiple empty selections,
getPlainTextToCopy()may return an array whose entries already include trailing line endings. The clipboard plain text payload was then built by joining those entries with another newline, which introduced blank lines when pasting into a single cursor.This change keeps
multicursorTextunchanged for multi-cursor paste distribution, but builds the plain text clipboard payload by concatenating the array entries directly.Test Plan