From fe5dcaefe3b95ef4dddc71638647ea31c103f9d2 Mon Sep 17 00:00:00 2001 From: CookedMelon Date: Tue, 13 Jan 2026 15:58:38 +0800 Subject: [PATCH 1/2] Fix paste escaping issue when cursor is inside string literals --- src/pasteEventHandler.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pasteEventHandler.ts b/src/pasteEventHandler.ts index 9606e19c23..c926e0d70f 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,20 @@ class PasteEditProvider implements DocumentPasteEditProvider { return null; } + // Skip paste handling for single line copies from the same document to avoid unwanted escaping + // in string literals when copying lines + const isSingleLineCopy = !insertText.includes('\n') && !insertText.includes('\r'); + const isFromSameDocument = this.copiedContent === insertText && this.copiedDocumentUri === document.uri.toString(); + if (isSingleLineCopy && isFromSameDocument) { + return undefined; // Let VS Code handle this normally + } + + // Skip paste handling when pasting content that contains quotes to avoid unwanted escaping + // This is a broader check than the above to handle cases where content is modified or from different documents + if (insertText.includes('"')) { + return undefined; // Let VS Code handle this normally + } + const range = ranges[0]; const location: Location = { From da20b1af9cac18f456131b7ee969c5c8f87bdfc3 Mon Sep 17 00:00:00 2001 From: CookedMelon <88501646+CookedMelon@users.noreply.github.com> Date: Tue, 13 Jan 2026 18:23:18 +0800 Subject: [PATCH 2/2] Refactor paste handling for single line copies --- src/pasteEventHandler.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/pasteEventHandler.ts b/src/pasteEventHandler.ts index c926e0d70f..c93cc0376a 100644 --- a/src/pasteEventHandler.ts +++ b/src/pasteEventHandler.ts @@ -74,20 +74,13 @@ class PasteEditProvider implements DocumentPasteEditProvider { return null; } - // Skip paste handling for single line copies from the same document to avoid unwanted escaping - // in string literals when copying lines - const isSingleLineCopy = !insertText.includes('\n') && !insertText.includes('\r'); + 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 } - // Skip paste handling when pasting content that contains quotes to avoid unwanted escaping - // This is a broader check than the above to handle cases where content is modified or from different documents - if (insertText.includes('"')) { - return undefined; // Let VS Code handle this normally - } - const range = ranges[0]; const location: Location = {