From 4fb22d76cf8354cb8b111d82bdfadea38c4b8f34 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Dec 2021 18:01:09 -0800 Subject: [PATCH] "Surround with" in TS/JS snippets (#138565) * Preserve selected text in snippets to provide "surround-with"-like functionality. * Add the same "surround with"-like functionality to JS snippets. --- .../snippets/javascript.code-snippets | 24 +++++++-------- .../snippets/typescript.code-snippets | 30 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/extensions/javascript/snippets/javascript.code-snippets b/extensions/javascript/snippets/javascript.code-snippets index a48a64c2813..ac5cd5549f1 100644 --- a/extensions/javascript/snippets/javascript.code-snippets +++ b/extensions/javascript/snippets/javascript.code-snippets @@ -17,7 +17,7 @@ "body": [ "for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {", "\tconst ${3:element} = ${2:array}[${1:index}];", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "For Loop" @@ -26,7 +26,7 @@ "prefix": "foreach", "body": [ "${1:array}.forEach(${2:element} => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "});" ], "description": "For-Each Loop" @@ -37,7 +37,7 @@ "for (const ${1:key} in ${2:object}) {", "\tif (Object.hasOwnProperty.call(${2:object}, ${1:key})) {", "\t\tconst ${3:element} = ${2:object}[${1:key}];", - "\t\t$0", + "\t\t$TM_SELECTED_TEXT$0", "\t}", "}" ], @@ -47,7 +47,7 @@ "prefix": "forof", "body": [ "for (const ${1:iterator} of ${2:object}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "For-Of Loop" @@ -56,7 +56,7 @@ "prefix": "function", "body": [ "function ${1:name}(${2:params}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "Function Statement" @@ -65,7 +65,7 @@ "prefix": "if", "body": [ "if (${1:condition}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "If Statement" @@ -74,7 +74,7 @@ "prefix": "ifelse", "body": [ "if (${1:condition}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "} else {", "\t", "}" @@ -106,7 +106,7 @@ "prefix": "while", "body": [ "while (${1:condition}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "While Statement" @@ -115,7 +115,7 @@ "prefix": "dowhile", "body": [ "do {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "} while (${1:condition});" ], "description": "Do-While Statement" @@ -124,7 +124,7 @@ "prefix": "trycatch", "body": [ "try {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "} catch (${1:error}) {", "\t", "}" @@ -135,7 +135,7 @@ "prefix": "settimeout", "body": [ "setTimeout(() => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}, ${1:timeout});" ], "description": "Set Timeout Function" @@ -144,7 +144,7 @@ "prefix": "setinterval", "body": [ "setInterval(() => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}, ${1:interval});" ], "description": "Set Interval Function" diff --git a/extensions/typescript-basics/snippets/typescript.code-snippets b/extensions/typescript-basics/snippets/typescript.code-snippets index 61155f40c41..49ebefbac9a 100644 --- a/extensions/typescript-basics/snippets/typescript.code-snippets +++ b/extensions/typescript-basics/snippets/typescript.code-snippets @@ -133,7 +133,7 @@ "body": [ "for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {", "\tconst ${3:element} = ${2:array}[${1:index}];", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "For Loop" @@ -142,7 +142,7 @@ "prefix": "foreach =>", "body": [ "${1:array}.forEach(${2:element} => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "});" ], "description": "For-Each Loop using =>" @@ -153,7 +153,7 @@ "for (const ${1:key} in ${2:object}) {", "\tif (Object.prototype.hasOwnProperty.call(${2:object}, ${1:key})) {", "\t\tconst ${3:element} = ${2:object}[${1:key}];", - "\t\t$0", + "\t\t$TM_SELECTED_TEXT$0", "\t}", "}" ], @@ -163,7 +163,7 @@ "prefix": "forof", "body": [ "for (const ${1:iterator} of ${2:object}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "For-Of Loop" @@ -172,7 +172,7 @@ "prefix": "forawaitof", "body": [ "for await (const ${1:iterator} of ${2:object}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "For-Await-Of Loop" @@ -181,7 +181,7 @@ "prefix": "function", "body": [ "function ${1:name}(${2:params}:${3:type}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "Function Statement" @@ -190,7 +190,7 @@ "prefix": "if", "body": [ "if (${1:condition}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "If Statement" @@ -199,7 +199,7 @@ "prefix": "ifelse", "body": [ "if (${1:condition}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "} else {", "\t", "}" @@ -231,7 +231,7 @@ "prefix": "while", "body": [ "while (${1:condition}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "While Statement" @@ -240,7 +240,7 @@ "prefix": "dowhile", "body": [ "do {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "} while (${1:condition});" ], "description": "Do-While Statement" @@ -249,7 +249,7 @@ "prefix": "trycatch", "body": [ "try {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "} catch (${1:error}) {", "\t", "}" @@ -260,7 +260,7 @@ "prefix": "settimeout", "body": [ "setTimeout(() => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}, ${1:timeout});" ], "description": "Set Timeout Function" @@ -283,7 +283,7 @@ "prefix": "newpromise", "body": [ "new Promise<${1:void}>((resolve, reject) => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "})" ], "description": "Create a new Promise" @@ -292,7 +292,7 @@ "prefix": "async function", "body": [ "async function ${1:name}(${2:params}:${3:type}) {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "Async Function Statement" @@ -301,7 +301,7 @@ "prefix": "async arrow function", "body": [ "async (${1:params}:${2:type}) => {", - "\t$0", + "\t$TM_SELECTED_TEXT$0", "}" ], "description": "Async Function Expression"