Skip to content

Commit fe5dcae

Browse files
committed
Fix paste escaping issue when cursor is inside string literals
1 parent 788a76e commit fe5dcae

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/pasteEventHandler.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PasteEditProvider implements DocumentPasteEditProvider {
5555
this.languageClient = languageClient;
5656
}
5757

58+
5859
async prepareDocumentPaste?(document: TextDocument, _ranges: readonly Range[], dataTransfer: DataTransfer, _token: CancellationToken): Promise<void> {
5960
const copiedContent: string = await dataTransfer.get(TEXT_MIMETYPE).asString();
6061
if (copiedContent) {
@@ -73,6 +74,20 @@ class PasteEditProvider implements DocumentPasteEditProvider {
7374
return null;
7475
}
7576

77+
// Skip paste handling for single line copies from the same document to avoid unwanted escaping
78+
// in string literals when copying lines
79+
const isSingleLineCopy = !insertText.includes('\n') && !insertText.includes('\r');
80+
const isFromSameDocument = this.copiedContent === insertText && this.copiedDocumentUri === document.uri.toString();
81+
if (isSingleLineCopy && isFromSameDocument) {
82+
return undefined; // Let VS Code handle this normally
83+
}
84+
85+
// Skip paste handling when pasting content that contains quotes to avoid unwanted escaping
86+
// This is a broader check than the above to handle cases where content is modified or from different documents
87+
if (insertText.includes('"')) {
88+
return undefined; // Let VS Code handle this normally
89+
}
90+
7691
const range = ranges[0];
7792

7893
const location: Location = {

0 commit comments

Comments
 (0)