From e38994929d186966e58b408a82edb4dad2ff83ab Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Sun, 30 Jan 2022 14:19:06 +0000 Subject: [PATCH] Fix multiple placeholders with the same name --- src/util/snippet.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/util/snippet.ts b/src/util/snippet.ts index 0ddedd1f2a4..d010adc4aad 100644 --- a/src/util/snippet.ts +++ b/src/util/snippet.ts @@ -22,7 +22,8 @@ export function transformSnippetVariables( placeholderName?: string | null, substitutions?: Record ) { - var placeholderIndex = getMaxPlaceholderIndex(parsedSnippet) + 1; + let nextPlaceholderIndex = getMaxPlaceholderIndex(parsedSnippet) + 1; + const placeholderIndexMap: Record = {}; parsedSnippet.walk((candidate) => { if (candidate instanceof Variable) { @@ -36,7 +37,13 @@ export function transformSnippetVariables( new Text(substitutions[candidate.name]), ]); } else if (!KnownSnippetVariableNames[candidate.name]) { - const placeholder = new Placeholder(placeholderIndex++); + let placeholderIndex: number; + if (candidate.name in placeholderIndexMap) { + placeholderIndex = placeholderIndexMap[candidate.name]; + } else { + placeholderIndex = nextPlaceholderIndex++; + } + const placeholder = new Placeholder(placeholderIndex); candidate.children.forEach((child) => placeholder.appendChild(child)); candidate.parent.replace(candidate, [placeholder]); }