fix: preserve line insertion behavior when paste providers handle full-line paste#306565
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: preserve line insertion behavior when paste providers handle full-line paste#306565yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…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
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.
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 thepasteOnNewLinemetadata.The default paste handler correctly uses
pasteOnNewLineto insert the line at column 1 (inserting above the current line), but theCopyPasteController's provider code path passes the original cursor position to providers without this adjustment.Closes #236799
What is the new behavior?
When
metadata.defaultPastePayload.pasteOnNewLineis 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:createCombinedWorkspaceEditapplies the insert text at the right positionThe 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 incursorTypeEditOperations.ts(PasteOperation._simplePaste) has always handledpasteOnNewLinecorrectly by adjusting the range to(lineNumber, 1, lineNumber, 1). But whenCopyPasteControllercallse.setHandled()to intercept the paste for providers, this adjustment was never applied to the selections passed downstream.