Skip to content

Commit 4fb22d7

Browse files
"Surround with" in TS/JS snippets (microsoft#138565)
* Preserve selected text in snippets to provide "surround-with"-like functionality. * Add the same "surround with"-like functionality to JS snippets.
1 parent 9744420 commit 4fb22d7

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

extensions/javascript/snippets/javascript.code-snippets

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"body": [
1818
"for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {",
1919
"\tconst ${3:element} = ${2:array}[${1:index}];",
20-
"\t$0",
20+
"\t$TM_SELECTED_TEXT$0",
2121
"}"
2222
],
2323
"description": "For Loop"
@@ -26,7 +26,7 @@
2626
"prefix": "foreach",
2727
"body": [
2828
"${1:array}.forEach(${2:element} => {",
29-
"\t$0",
29+
"\t$TM_SELECTED_TEXT$0",
3030
"});"
3131
],
3232
"description": "For-Each Loop"
@@ -37,7 +37,7 @@
3737
"for (const ${1:key} in ${2:object}) {",
3838
"\tif (Object.hasOwnProperty.call(${2:object}, ${1:key})) {",
3939
"\t\tconst ${3:element} = ${2:object}[${1:key}];",
40-
"\t\t$0",
40+
"\t\t$TM_SELECTED_TEXT$0",
4141
"\t}",
4242
"}"
4343
],
@@ -47,7 +47,7 @@
4747
"prefix": "forof",
4848
"body": [
4949
"for (const ${1:iterator} of ${2:object}) {",
50-
"\t$0",
50+
"\t$TM_SELECTED_TEXT$0",
5151
"}"
5252
],
5353
"description": "For-Of Loop"
@@ -56,7 +56,7 @@
5656
"prefix": "function",
5757
"body": [
5858
"function ${1:name}(${2:params}) {",
59-
"\t$0",
59+
"\t$TM_SELECTED_TEXT$0",
6060
"}"
6161
],
6262
"description": "Function Statement"
@@ -65,7 +65,7 @@
6565
"prefix": "if",
6666
"body": [
6767
"if (${1:condition}) {",
68-
"\t$0",
68+
"\t$TM_SELECTED_TEXT$0",
6969
"}"
7070
],
7171
"description": "If Statement"
@@ -74,7 +74,7 @@
7474
"prefix": "ifelse",
7575
"body": [
7676
"if (${1:condition}) {",
77-
"\t$0",
77+
"\t$TM_SELECTED_TEXT$0",
7878
"} else {",
7979
"\t",
8080
"}"
@@ -106,7 +106,7 @@
106106
"prefix": "while",
107107
"body": [
108108
"while (${1:condition}) {",
109-
"\t$0",
109+
"\t$TM_SELECTED_TEXT$0",
110110
"}"
111111
],
112112
"description": "While Statement"
@@ -115,7 +115,7 @@
115115
"prefix": "dowhile",
116116
"body": [
117117
"do {",
118-
"\t$0",
118+
"\t$TM_SELECTED_TEXT$0",
119119
"} while (${1:condition});"
120120
],
121121
"description": "Do-While Statement"
@@ -124,7 +124,7 @@
124124
"prefix": "trycatch",
125125
"body": [
126126
"try {",
127-
"\t$0",
127+
"\t$TM_SELECTED_TEXT$0",
128128
"} catch (${1:error}) {",
129129
"\t",
130130
"}"
@@ -135,7 +135,7 @@
135135
"prefix": "settimeout",
136136
"body": [
137137
"setTimeout(() => {",
138-
"\t$0",
138+
"\t$TM_SELECTED_TEXT$0",
139139
"}, ${1:timeout});"
140140
],
141141
"description": "Set Timeout Function"
@@ -144,7 +144,7 @@
144144
"prefix": "setinterval",
145145
"body": [
146146
"setInterval(() => {",
147-
"\t$0",
147+
"\t$TM_SELECTED_TEXT$0",
148148
"}, ${1:interval});"
149149
],
150150
"description": "Set Interval Function"

extensions/typescript-basics/snippets/typescript.code-snippets

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"body": [
134134
"for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {",
135135
"\tconst ${3:element} = ${2:array}[${1:index}];",
136-
"\t$0",
136+
"\t$TM_SELECTED_TEXT$0",
137137
"}"
138138
],
139139
"description": "For Loop"
@@ -142,7 +142,7 @@
142142
"prefix": "foreach =>",
143143
"body": [
144144
"${1:array}.forEach(${2:element} => {",
145-
"\t$0",
145+
"\t$TM_SELECTED_TEXT$0",
146146
"});"
147147
],
148148
"description": "For-Each Loop using =>"
@@ -153,7 +153,7 @@
153153
"for (const ${1:key} in ${2:object}) {",
154154
"\tif (Object.prototype.hasOwnProperty.call(${2:object}, ${1:key})) {",
155155
"\t\tconst ${3:element} = ${2:object}[${1:key}];",
156-
"\t\t$0",
156+
"\t\t$TM_SELECTED_TEXT$0",
157157
"\t}",
158158
"}"
159159
],
@@ -163,7 +163,7 @@
163163
"prefix": "forof",
164164
"body": [
165165
"for (const ${1:iterator} of ${2:object}) {",
166-
"\t$0",
166+
"\t$TM_SELECTED_TEXT$0",
167167
"}"
168168
],
169169
"description": "For-Of Loop"
@@ -172,7 +172,7 @@
172172
"prefix": "forawaitof",
173173
"body": [
174174
"for await (const ${1:iterator} of ${2:object}) {",
175-
"\t$0",
175+
"\t$TM_SELECTED_TEXT$0",
176176
"}"
177177
],
178178
"description": "For-Await-Of Loop"
@@ -181,7 +181,7 @@
181181
"prefix": "function",
182182
"body": [
183183
"function ${1:name}(${2:params}:${3:type}) {",
184-
"\t$0",
184+
"\t$TM_SELECTED_TEXT$0",
185185
"}"
186186
],
187187
"description": "Function Statement"
@@ -190,7 +190,7 @@
190190
"prefix": "if",
191191
"body": [
192192
"if (${1:condition}) {",
193-
"\t$0",
193+
"\t$TM_SELECTED_TEXT$0",
194194
"}"
195195
],
196196
"description": "If Statement"
@@ -199,7 +199,7 @@
199199
"prefix": "ifelse",
200200
"body": [
201201
"if (${1:condition}) {",
202-
"\t$0",
202+
"\t$TM_SELECTED_TEXT$0",
203203
"} else {",
204204
"\t",
205205
"}"
@@ -231,7 +231,7 @@
231231
"prefix": "while",
232232
"body": [
233233
"while (${1:condition}) {",
234-
"\t$0",
234+
"\t$TM_SELECTED_TEXT$0",
235235
"}"
236236
],
237237
"description": "While Statement"
@@ -240,7 +240,7 @@
240240
"prefix": "dowhile",
241241
"body": [
242242
"do {",
243-
"\t$0",
243+
"\t$TM_SELECTED_TEXT$0",
244244
"} while (${1:condition});"
245245
],
246246
"description": "Do-While Statement"
@@ -249,7 +249,7 @@
249249
"prefix": "trycatch",
250250
"body": [
251251
"try {",
252-
"\t$0",
252+
"\t$TM_SELECTED_TEXT$0",
253253
"} catch (${1:error}) {",
254254
"\t",
255255
"}"
@@ -260,7 +260,7 @@
260260
"prefix": "settimeout",
261261
"body": [
262262
"setTimeout(() => {",
263-
"\t$0",
263+
"\t$TM_SELECTED_TEXT$0",
264264
"}, ${1:timeout});"
265265
],
266266
"description": "Set Timeout Function"
@@ -283,7 +283,7 @@
283283
"prefix": "newpromise",
284284
"body": [
285285
"new Promise<${1:void}>((resolve, reject) => {",
286-
"\t$0",
286+
"\t$TM_SELECTED_TEXT$0",
287287
"})"
288288
],
289289
"description": "Create a new Promise"
@@ -292,7 +292,7 @@
292292
"prefix": "async function",
293293
"body": [
294294
"async function ${1:name}(${2:params}:${3:type}) {",
295-
"\t$0",
295+
"\t$TM_SELECTED_TEXT$0",
296296
"}"
297297
],
298298
"description": "Async Function Statement"
@@ -301,7 +301,7 @@
301301
"prefix": "async arrow function",
302302
"body": [
303303
"async (${1:params}:${2:type}) => {",
304-
"\t$0",
304+
"\t$TM_SELECTED_TEXT$0",
305305
"}"
306306
],
307307
"description": "Async Function Expression"

0 commit comments

Comments
 (0)