Skip to content

Commit f962aba

Browse files
Indent all lines of single JsxText node
1 parent ce25dc9 commit f962aba

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/services/formatting/formatting.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ namespace ts.formatting {
714714

715715
processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);
716716

717+
if (child.kind === SyntaxKind.JsxText) {
718+
const range = { pos: child.getStart(), end: child.getEnd() };
719+
indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false);
720+
}
721+
717722
childContextNode = node;
718723

719724
if (isFirstListItem && parent.kind === SyntaxKind.ArrayLiteralExpression && inheritedIndentation === Constants.Unknown) {
@@ -833,7 +838,7 @@ namespace ts.formatting {
833838
switch (triviaItem.kind) {
834839
case SyntaxKind.MultiLineCommentTrivia:
835840
if (triviaInRange) {
836-
indentMultilineComment(triviaItem, commentIndentation, /*firstLineIsIndented*/ !indentNextTokenOrTrivia);
841+
indentMultilineCommentOrJsxText(triviaItem, commentIndentation, /*firstLineIsIndented*/ !indentNextTokenOrTrivia);
837842
}
838843
indentNextTokenOrTrivia = false;
839844
break;
@@ -985,7 +990,7 @@ namespace ts.formatting {
985990
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
986991
}
987992

988-
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
993+
function indentMultilineCommentOrJsxText(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean, indentFinalLine = true) {
989994
// split comment in lines
990995
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
991996
const endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
@@ -1006,7 +1011,9 @@ namespace ts.formatting {
10061011
startPos = getStartPositionOfLine(line + 1, sourceFile);
10071012
}
10081013

1009-
parts.push({ pos: startPos, end: commentRange.end });
1014+
if (indentFinalLine) {
1015+
parts.push({ pos: startPos, end: commentRange.end });
1016+
}
10101017
}
10111018

10121019
const startLinePos = getStartPositionOfLine(startLine, sourceFile);

0 commit comments

Comments
 (0)