diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 2d14b1cab19..5c0c1184ac7 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -137,6 +137,9 @@ // e.g. * ...| or */| or *-----*/| "unIndentedLinePattern": { "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" + }, + "indentNextLinePattern": { + "pattern": "^.*[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 6ef21225b56..b91ef13839a 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -672,15 +672,13 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); - test.skip('issue #43244: incorrect indentation', () => { + test('issue #43244: incorrect indentation', () => { // 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); @@ -688,13 +686,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)', + ' ', + '}', + ].join('\n')); + + viewModel.type("return;"); viewModel.type("\n", 'keyboard'); assert.strictEqual(model.getValue(), [ 'function f() {', ' if (condition)', ' return;', - '', + ' ', '}', ].join('\n')); @@ -703,8 +710,8 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { '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 12fb83c4925..d448df7e91f 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -7,5 +7,6 @@ export const javascriptIndentationRules = { decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/, increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| - unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/ + unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, + indentNextLinePattern: /^.*[if|while|for]\s*\(.*\)\s*/ };