Skip to content

Commit 54b8c73

Browse files
committed
when looking for a start node consider only nodes that can contribute to indentation
1 parent cd663f0 commit 54b8c73

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ module ts.formatting {
3535
}
3636
}
3737

38-
// try to find the node that will include 'position' starting from 'precedingToken'
38+
// try to find node that can contribute to indentation and includes 'position' starting from 'precedingToken'
3939
// if such node is found - compute initial indentation for 'position' inside this node
4040
var previous: Node;
4141
var current = precedingToken;
4242
var currentStart: LineAndCharacter;
4343
var indentation: number;
4444

4545
while (current) {
46-
if (isPositionBelongToNode(current, position, sourceFile)) {
46+
if (isPositionBelongToNode(current, position, sourceFile) && isNodeContentIndented(current, previous)) {
4747
currentStart = getStartLineAndCharacterForNode(current, sourceFile);
4848

4949
if (discardInitialIndentationIfNextTokenIsOpenOrCloseBrace(precedingToken, current, lineAtPosition, sourceFile)) {
5050
indentation = 0;
5151
}
5252
else {
53-
indentation = isNodeContentIndented(current, previous) && lineAtPosition !== currentStart.line ? options.indentSpaces : 0;
53+
indentation = lineAtPosition !== currentStart.line ? options.indentSpaces : 0;
5454
}
5555

5656
break;
@@ -444,7 +444,6 @@ module ts.formatting {
444444
case SyntaxKind.DefaultClause:
445445
case SyntaxKind.CaseClause:
446446
case SyntaxKind.ParenExpression:
447-
case SyntaxKind.BinaryExpression:
448447
case SyntaxKind.CallExpression:
449448
case SyntaxKind.NewExpression:
450449
case SyntaxKind.VariableStatement:

0 commit comments

Comments
 (0)