diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 25d58a59d3e..070b8911a82 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -139,7 +139,7 @@ "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" }, "indentNextLinePattern": { - "pattern": "^.*=>\\s*$" + "pattern": "^((.*=>\\s*)|((.*[^\\w]+|\\s*)(if|while|for)\\s*\\(.*\\)\\s*))$" } }, "onEnterRules": [ diff --git a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts index 7b26a3af664..cb3663522a7 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -663,15 +663,13 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); - test.skip('issue #43244: incorrect indentation', () => { + test('issue #43244: incorrect indentation after if/for/while without braces', () => { // https://github.com/microsoft/vscode/issues/43244 - // potential regex to fix: "^.*[if|while|for]\s*\(.*\)\s*", const model = createTextModel([ 'function f() {', ' if (condition)', - ' return;', '}' ].join('\n'), languageId, {}); disposables.add(model); @@ -679,23 +677,22 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => { registerLanguage(instantiationService, languageId, Language.TypeScript, disposables); - editor.setSelection(new Selection(3, 16, 3, 16)); + editor.setSelection(new Selection(2, 19, 2, 19)); viewModel.type("\n", 'keyboard'); assert.strictEqual(model.getValue(), [ 'function f() {', ' if (condition)', - ' return;', - '', + ' ', '}', ].join('\n')); + viewModel.type("return;"); viewModel.type("\n", 'keyboard'); assert.strictEqual(model.getValue(), [ 'function f() {', ' if (condition)', ' return;', - '', - '', + ' ', '}', ].join('\n')); }); diff --git a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts index 83c073a8bf6..9842856423d 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -8,5 +8,5 @@ export const javascriptIndentationRules = { increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, - indentNextLinePattern: /^.*=>\s*$/, + indentNextLinePattern: /^((.*=>\s*)|((.*[^\w]+|\s*)(if|while|for)\s*\(.*\)\s*))$/, };