Skip to content

Commit 2878325

Browse files
committed
auto escape strings based on preceding character
1 parent 36ec5d4 commit 2878325

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/features/translation.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ export const completionProvider = {
252252
getTranslations().items.translations,
253253
).length;
254254

255+
const precedingCharacter = document.getText(
256+
new vscode.Range(
257+
position.line,
258+
position.character - 1,
259+
position.line,
260+
position.character,
261+
),
262+
);
263+
255264
return Object.entries(getTranslations().items.translations).map(
256265
([key, translations]) => {
257266
let completionItem = new vscode.CompletionItem(
@@ -264,6 +273,12 @@ export const completionProvider = {
264273
wordMatchRegex,
265274
);
266275

276+
if (precedingCharacter === "'") {
277+
completionItem.insertText = key.replaceAll("'", "\\'");
278+
} else if (precedingCharacter === '"') {
279+
completionItem.insertText = key.replaceAll('"', '\\"');
280+
}
281+
267282
if (totalTranslationItems < 200) {
268283
// This will bomb if we have too many translations,
269284
// 200 is an arbitrary but probably safe number

0 commit comments

Comments
 (0)