Skip to content

Commit 655bf20

Browse files
committed
indent using list start position before first list item
1 parent cd19a89 commit 655bf20

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ namespace ts.formatting {
6666
}
6767
}
6868

69+
const containerList = getListByPosition(position, precedingToken.parent);
70+
// use list position if the preceding token is before any list items
71+
if (containerList && !rangeContainsRange(containerList, precedingToken)) {
72+
return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize;
73+
}
74+
6975
return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options);
7076
}
7177

@@ -394,6 +400,13 @@ namespace ts.formatting {
394400
}
395401
}
396402

403+
function getActualIndentationForListStartLine(list: NodeArray<Node>, sourceFile: SourceFile, options: EditorSettings): number {
404+
if (!list) {
405+
return Value.Unknown;
406+
}
407+
return findColumnForFirstNonWhitespaceCharacterInLine(sourceFile.getLineAndCharacterOfPosition(list.pos), sourceFile, options);
408+
}
409+
397410
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorSettings): number {
398411
const containingList = getContainingList(node, sourceFile);
399412
if (containingList) {

0 commit comments

Comments
 (0)