Skip to content

fix: preserve line insertion behavior when paste providers handle full-line paste#306565

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/paste-with-imports-line-insertion-v2
Open

fix: preserve line insertion behavior when paste providers handle full-line paste#306565
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/paste-with-imports-line-insertion-v2

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When copying a full line (empty selection, Ctrl+C) that contains an importable symbol and pasting it into another file (Ctrl+V, also with empty selection), the text is inserted at the cursor column instead of at the beginning of the line. This happens because paste providers like TypeScript's "paste with imports" intercept the paste and apply edits at the cursor position, ignoring the pasteOnNewLine metadata.

The default paste handler correctly uses pasteOnNewLine to insert the line at column 1 (inserting above the current line), but the CopyPasteController's provider code path passes the original cursor position to providers without this adjustment.

Closes #236799

What is the new behavior?

When metadata.defaultPastePayload.pasteOnNewLine is true and all selections are empty (matching the conditions in the default paste handler), the selections are adjusted to column 1 before being passed to paste providers. This ensures that:

  1. Providers receive the correct paste location (beginning of line)
  2. createCombinedWorkspaceEdit applies the insert text at the right position
  3. The TypeScript server computes additional edits (import additions) relative to the correct insertion point

The fix is a 7-line addition in CopyPasteController.doPasteInline(), applied before any provider interaction.

Additional context

The root cause is in src/vs/editor/contrib/dropOrPasteInto/browser/copyPasteController.ts. The default paste handler in cursorTypeEditOperations.ts (PasteOperation._simplePaste) has always handled pasteOnNewLine correctly by adjusting the range to (lineNumber, 1, lineNumber, 1). But when CopyPasteController calls e.setHandled() to intercept the paste for providers, this adjustment was never applied to the selections passed downstream.

…l-line paste

When copying a full line (no selection) and pasting with paste providers
active (e.g. TypeScript paste-with-imports), the paste was inserted at
the cursor column instead of at the beginning of the line. The default
paste handler correctly uses pasteOnNewLine metadata to insert at column
1, but the CopyPasteController's provider path did not account for this.

Adjust paste ranges to column 1 when pasteOnNewLine is true and all
selections are empty, so that paste providers receive and apply edits at
the correct line-start position.

Closes microsoft#236799
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.

The new paste with imports feature broke line insertion

2 participants