Skip to content

Commit ea0ec9f

Browse files
committed
adding regexes in order to indent when inside of (), {} or []
1 parent 6bc3ed7 commit ea0ec9f

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

extensions/typescript-basics/language-configuration.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,33 @@
215215
"action": {
216216
"indent": "outdent"
217217
}
218-
}
218+
},
219+
// Indent when pressing enter from inside ()
220+
{
221+
"beforeText": "^.*\\([^\\)]*$",
222+
"afterText": "^[^\\(]*\\).*$",
223+
"action": {
224+
"indent": "indentOutdent",
225+
"appendText": "\t",
226+
}
227+
},
228+
// Indent when pressing enter from inside {}
229+
{
230+
"beforeText": "^.*\\{[^\\}]*$",
231+
"afterText": "^[^\\{]*\\}.*$",
232+
"action": {
233+
"indent": "indentOutdent",
234+
"appendText": "\t",
235+
}
236+
},
237+
// Indent when pressing enter from inside []
238+
{
239+
"beforeText": "^.*\\[[^\\]]*$",
240+
"afterText": "^[^\\[]*\\].*$",
241+
"action": {
242+
"indent": "indentOutdent",
243+
"appendText": "\t",
244+
}
245+
},
219246
]
220247
}

src/vs/workbench/contrib/codeEditor/test/node/autoindent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ suite('Auto-Reindentation - TypeScript/JavaScript', () => {
190190
// explanation: if (, [, {, is followed by a forward slash then assume we are in a regex pattern, and do not indent
191191

192192
// increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/ -> /^((?!\/\/).)*(\{([^}"'`/]*|(\t|[ ])*\/\/.*)|\([^)"'`/]*|\[[^\]"'`/]*)$/
193-
// -> Final current increase indent pattern
193+
// -> Final current increase indent pattern at of writing
194194

195195
const fileContents = [
196196
'const r = /{/;',
@@ -214,7 +214,7 @@ suite('Auto-Reindentation - TypeScript/JavaScript', () => {
214214
// fix: https://github.com/microsoft/vscode/commit/7910b3d7bab8a721aae98dc05af0b5e1ea9d9782
215215

216216
// decreaseIndentPattern: /^(.*\*\/)?\s*[\}\]\)].*$/ -> /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/
217-
// -> Final current decrease indent pattern
217+
// -> Final current decrease indent pattern at the time of writing
218218

219219
// explanation: Positive lookahead: (?= «pattern») matches if pattern matches what comes after the current location in the input string.
220220
// Negative lookahead: (?! «pattern») matches if pattern does not match what comes after the current location in the input string

0 commit comments

Comments
 (0)