From 1a46978239b30dcf36d7b7a57f88f9bbc125e1f9 Mon Sep 17 00:00:00 2001 From: James Yu Date: Sun, 13 Oct 2024 20:50:04 +0800 Subject: [PATCH] Fix #4430 Escape $ when surround macros --- src/completion/completer/macro.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/completion/completer/macro.ts b/src/completion/completer/macro.ts index d674fb652..803866769 100644 --- a/src/completion/completer/macro.ts +++ b/src/completion/completer/macro.ts @@ -187,12 +187,12 @@ function surround(cmdItems?: CompletionItem[]) { } void editor.edit( editBuilder => { for (const selection of editor.selections) { - const selectedContent = editor.document.getText(selection) + const selectedContent = editor.document.getText(selection).replaceAll('$', '$$$$') const selectedMacro = '\\' + selected.macro editBuilder.replace(new vscode.Range(selection.start, selection.end), - selectedMacro.replace(/(.*)(\${\d.*?})/, `$1${selectedContent}`) // Replace text - .replace(/\${\d:?(.*?)}/g, '$1') // Remove snippet placeholders - .replace(/\$\d/, '')) // Remove $2 etc + selectedMacro.replace(/\$\d/g, '') // Remove $2 etc + .replace(/(.*)(\${\d.*?})/g, `$1${selectedContent}`) // Replace text + .replace(/\${\d:?(.*?)}/g, '$1')) // Remove snippet placeholders } }) })