@@ -323,6 +323,9 @@ module ts.formatting {
323
323
let previousParent : Node ;
324
324
let previousRangeStartLine : number ;
325
325
326
+ let lastIndentedLine : number ;
327
+ let indentationOnLastIndentedLine : number ;
328
+
326
329
let edits : TextChange [ ] = [ ] ;
327
330
328
331
formattingScanner . advance ( ) ;
@@ -416,7 +419,9 @@ module ts.formatting {
416
419
// if node is located on the same line with the parent
417
420
// - inherit indentation from the parent
418
421
// - push children if either parent of node itself has non-zero delta
419
- indentation = parentDynamicIndentation . getIndentation ( ) ;
422
+ indentation = startLine === lastIndentedLine
423
+ ? indentationOnLastIndentedLine
424
+ : parentDynamicIndentation . getIndentation ( ) ;
420
425
delta = Math . min ( options . IndentSize , parentDynamicIndentation . getDelta ( ) + delta ) ;
421
426
}
422
427
return {
@@ -716,7 +721,6 @@ module ts.formatting {
716
721
continue ;
717
722
}
718
723
719
- let triviaStartLine = sourceFile . getLineAndCharacterOfPosition ( triviaItem . pos ) . line ;
720
724
switch ( triviaItem . kind ) {
721
725
case SyntaxKind . MultiLineCommentTrivia :
722
726
let commentIndentation = dynamicIndentation . getIndentationForComment ( currentTokenInfo . token . kind ) ;
@@ -741,6 +745,9 @@ module ts.formatting {
741
745
if ( isTokenInRange && ! rangeContainsError ( currentTokenInfo . token ) ) {
742
746
let tokenIndentation = dynamicIndentation . getIndentationForToken ( tokenStart . line , currentTokenInfo . token . kind ) ;
743
747
insertIndentation ( currentTokenInfo . token . pos , tokenIndentation , lineAdded ) ;
748
+
749
+ lastIndentedLine = tokenStart . line ;
750
+ indentationOnLastIndentedLine = tokenIndentation ;
744
751
}
745
752
}
746
753
0 commit comments