Skip to content

Fix blank lines when copying multiple empty selections#324294

Open
CHENJIAMIAN wants to merge 2 commits into
microsoft:mainfrom
CHENJIAMIAN:fix-empty-selection-copy-blank-lines
Open

Fix blank lines when copying multiple empty selections#324294
CHENJIAMIAN wants to merge 2 commits into
microsoft:mainfrom
CHENJIAMIAN:fix-empty-selection-copy-blank-lines

Conversation

@CHENJIAMIAN

Copy link
Copy Markdown

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 multicursorText unchanged for multi-cursor paste distribution, but builds the plain text clipboard payload by concatenating the array entries directly.

Test Plan

  • Added a regression test for copying from multiple empty selections and pasting into a single cursor.
  • Did not run the full VS Code test suite locally because this machine is missing the native C/C++ toolchain required by the repository preinstall checks.

Copilot AI review requested due to automatic review settings July 4, 2026 08:47

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.

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 getDataToCopy from sourceText.join(newLineCharacter) to sourceText.join('') and removed the now-unused newLineCharacter local.
  • Added a regression test in cursor.test.ts for 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);
@CHENJIAMIAN

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@CHENJIAMIAN

Copy link
Copy Markdown
Author

Updated this PR to handle mixed selections as well.

What changed:

  • The plain text clipboard payload now only inserts an EOL separator between chunks when the previous chunk does not already end with one.
  • Added a regression test for the mixed non-empty + empty selection case (['ine2', 'line3\n'] => ine2\nline3\n).

This keeps the #256039 multi-cursor distribution behavior, fixes #324290, and avoids regressing mixed-selection copy.

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.

Copying multiple empty selections adds blank lines when pasted into a single cursor

3 participants