diff --git a/src/pasteEventHandler.ts b/src/pasteEventHandler.ts index 9606e19c2..c93cc0376 100644 --- a/src/pasteEventHandler.ts +++ b/src/pasteEventHandler.ts @@ -55,6 +55,7 @@ class PasteEditProvider implements DocumentPasteEditProvider { this.languageClient = languageClient; } + async prepareDocumentPaste?(document: TextDocument, _ranges: readonly Range[], dataTransfer: DataTransfer, _token: CancellationToken): Promise { const copiedContent: string = await dataTransfer.get(TEXT_MIMETYPE).asString(); if (copiedContent) { @@ -73,6 +74,13 @@ class PasteEditProvider implements DocumentPasteEditProvider { return null; } + const editorData = dataTransfer.get("vscode-editor-data")?.value; + const isSingleLineCopy = Boolean(editorData && JSON.parse(editorData).isFromEmptySelection); + const isFromSameDocument = this.copiedContent === insertText && this.copiedDocumentUri === document.uri.toString(); + if (isSingleLineCopy && isFromSameDocument) { + return undefined; // Let VS Code handle this normally + } + const range = ranges[0]; const location: Location = {