8000 new lines that were added\removed by rules must always be honores eve… · Nemo157/TypeScript@cca6eea · GitHub
[go: up one dir, main page]

Skip to content

Commit cca6eea

Browse files
committed
new lines that were added\removed by rules must always be honores even if they doesn't trigger recomputation of indentation
1 parent 05fd2e9 commit cca6eea

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/services/formatting.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,25 +701,23 @@ module ts.formatting {
701701
applyRuleEdits(rule, previousItem, previousStartLine, currentItem, currentStartLine);
702702

703703
if (rule.Operation.Action & (RuleAction.Space | RuleAction.Delete) && currentStartLine !== previousStartLine) {
704+
lineAdded = false;
704705
// Handle the case where the next line is moved to be the end of this line.
705706
// In this case we don't indent the next line in the next pass.
706707
if (currentParent.getStart(sourceFile) === currentItem.pos) {
707-
lineAdded = false;
708+
dynamicIndentation.recomputeIndentation(/*lineAdded*/ false);
708709
}
709710
}
710711
else if (rule.Operation.Action & RuleAction.NewLine && currentStartLine === previousStartLine) {
712+
lineAdded = true;
711713
// Handle the case where token2 is moved to the new line.
712714
// In this case we indent token2 in the next pass but we set
713715
// sameLineIndent flag to notify the indenter that the indentation is within the line.
714716
if (currentParent.getStart(sourceFile) === currentItem.pos) {
715-
lineAdded = true;
717+
dynamicIndentation.recomputeIndentation(/*lineAdded*/ true);
716718
}
717719
}
718720

719-
if (lineAdded !== undefined) {
720-
dynamicIndentation.recomputeIndentation(lineAdded);
721-
}
722-
723721
// 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
724722
trimTrailingWhitespaces =
725723
(rule.Operation.Action & (RuleAction.NewLine | RuleAction.Space)) &&
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////module A
4+
////{
5+
//// class B {
6+
//// /*1*/
7+
////}
8+
9+
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
10+
format.setOption("PlaceOpenBraceOnNewLineForFunctions", true);
11+
goTo.marker("1");
12+
edit.insert("}");
13+
14+
verify.currentFileContentIs(
15+
"module A\n\
16+
{\n\
17+
class B\n\
18+
{\n\
19+
}\n\
20+
}"
21+
);

0 commit comments

Comments
 (0)
0