From b2cfddbe7a30c05ebac112af556974fa16913a9e Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Sun, 13 Sep 2015 23:42:24 +0900 Subject: [PATCH] re-fix token indentation --- src/services/formatting/formatting.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index eeebfd1649d..9f300f1db7a 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -60,6 +60,11 @@ namespace ts.formatting { * so indentation scope can adjust values of indentation and delta. */ recomputeIndentation(lineAddedByFormatting: boolean): void; + + /** + * Returns DynamicIndentation object that includes modified delta value for specific child node. + */ + getCopyForSpecificChild(child: Node): DynamicIndentation; } interface Indentation { @@ -475,14 +480,7 @@ namespace ts.formatting { } }, getIndentation: () => indentation, - getDelta: (child: TextRangeWithKind) => { - if (SmartIndenter.shouldInheritParentIndentation(node, child)) { - return 0; - } - else { - return delta; - } - }, + getDelta: (child) => (!delta || SmartIndenter.shouldInheritParentIndentation(node, child)) ? 0 : delta, recomputeIndentation: lineAdded => { if (node.parent && SmartIndenter.shouldIndentChildNode(node.parent, node)) { if (lineAdded) { @@ -500,6 +498,13 @@ namespace ts.formatting { } } }, + getCopyForSpecificChild(child) { + if (!delta) { + // delta value is already 0, so do not copy + return this; + } + return getDynamicIndentation(node, nodeStartLine, indentation, (this).getDelta(child)); + } } } @@ -599,7 +604,7 @@ namespace ts.formatting { // if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules let tokenInfo = formattingScanner.readTokenInfo(child); Debug.assert(tokenInfo.token.end === child.end); - consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation); + consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation.getCopyForSpecificChild(child)); return inheritedIndentation; }