diff --git a/src/services/formatting.ts b/src/services/formatting.ts index f58f1ccb33e..fc64329c3e0 100644 --- a/src/services/formatting.ts +++ b/src/services/formatting.ts @@ -701,25 +701,23 @@ module ts.formatting { applyRuleEdits(rule, previousItem, previousStartLine, currentItem, currentStartLine); if (rule.Operation.Action & (RuleAction.Space | RuleAction.Delete) && currentStartLine !== previousStartLine) { + lineAdded = false; // Handle the case where the next line is moved to be the end of this line. // In this case we don't indent the next line in the next pass. if (currentParent.getStart(sourceFile) === currentItem.pos) { - lineAdded = false; + dynamicIndentation.recomputeIndentation(/*lineAdded*/ false); } } else if (rule.Operation.Action & RuleAction.NewLine && currentStartLine === previousStartLine) { + lineAdded = true; // Handle the case where token2 is moved to the new line. // In this case we indent token2 in the next pass but we set // sameLineIndent flag to notify the indenter that the indentation is within the line. if (currentParent.getStart(sourceFile) === currentItem.pos) { - lineAdded = true; + dynamicIndentation.recomputeIndentation(/*lineAdded*/ true); } } - if (lineAdded !== undefined) { - dynamicIndentation.recomputeIndentation(lineAdded); - } - // We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line trimTrailingWhitespaces = (rule.Operation.Action & (RuleAction.NewLine | RuleAction.Space)) && diff --git a/tests/cases/fourslash/formatNestedClassWithOpenBraceOnNewLines.ts b/tests/cases/fourslash/formatNestedClassWithOpenBraceOnNewLines.ts new file mode 100644 index 00000000000..2f3157a2833 --- /dev/null +++ b/tests/cases/fourslash/formatNestedClassWithOpenBraceOnNewLines.ts @@ -0,0 +1,21 @@ +/// + +////module A +////{ +//// class B { +//// /*1*/ +////} + +format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true); +format.setOption("PlaceOpenBraceOnNewLineForFunctions", true); +goTo.marker("1"); +edit.insert("}"); + +verify.currentFileContentIs( +"module A\n\ +{\n\ + class B\n\ + {\n\ + }\n\ +}" +); \ No newline at end of file