Skip to content

Commit 43a4526

Browse files
committed
indent using list start position before first list item
1 parent f64237f commit 43a4526

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
@@ -72,6 +72,12 @@ namespace ts.formatting {
7272
}
7373
}
7474

75+
const containerList = getListByPosition(position, precedingToken.parent);
76+
// use list position if the preceding token is before any list items
77+
if (containerList && !rangeContainsRange(containerList, precedingToken)) {
78+
return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize;
79+
}
80+
7581
// try to find node that can contribute to indentation and includes 'position' starting from 'precedingToken'
7682
// if such node is found - compute initial indentation for 'position' inside this node
7783
let previous: Node;
@@ -342,6 +348,13 @@ namespace ts.formatting {
342348
}
343349
}
344350

351+
function getActualIndentationForListStartLine(list: NodeArray<Node>, sourceFile: SourceFile, options: EditorSettings): number {
352+
if (!list) {
353+
return Value.Unknown;
354+
}
355+
return findColumnForFirstNonWhitespaceCharacterInLine(sourceFile.getLineAndCharacterOfPosition(list.pos), sourceFile, options);
356+
}
357+
345358
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorSettings): number {
346359
const containingList = getContainingList(node, sourceFile);
347360
return containingList ? getActualIndentationFromList(containingList) : Value.Unknown;

0 commit comments

Comments
 (0)