* Replaces the snippet variable with name `placeholderName` with TM_SELECTED_TEXT * * Also replaces any unknown variables with placeholders. We do this so it's * easier to leave one of the placeholders blank. We may make it so that you * can disable this with a setting in the future * @param pa
( parsedSnippet: TextmateSnippet, placeholderName: string )
| 126 | * @param placeholderName The variable name to replace with TM_SELECTED_TEXT |
| 127 | */ |
| 128 | function transformSnippetVariables( |
| 129 | parsedSnippet: TextmateSnippet, |
| 130 | placeholderName: string |
| 131 | ) { |
| 132 | var placeholderIndex = getMaxPlaceholderIndex(parsedSnippet) + 1; |
| 133 | |
| 134 | parsedSnippet.walk((candidate) => { |
| 135 | if (candidate instanceof Variable) { |
| 136 | if (candidate.name === placeholderName) { |
| 137 | candidate.name = "TM_SELECTED_TEXT"; |
| 138 | } else if (!KnownSnippetVariableNames[candidate.name]) { |
| 139 | const placeholder = new Placeholder(placeholderIndex++); |
| 140 | candidate.children.forEach((child) => placeholder.appendChild(child)); |
| 141 | candidate.parent.replace(candidate, [placeholder]); |
| 142 | } |
| 143 | } |
| 144 | return true; |
| 145 | }); |
| 146 | } |
| 147 | |
| 148 | function getMaxPlaceholderIndex(parsedSnippet: TextmateSnippet) { |
| 149 | var placeholderIndex = 0; |
no test coverage detected