From 655bf203d0ed74db87b78edf3d9cfeda95cb0618 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 30 May 2017 03:16:10 +0900 Subject: [PATCH] indent using list start position before first list item --- src/services/formatting/smartIndenter.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 8cd95e04de8..9f4b527d782 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -66,6 +66,12 @@ namespace ts.formatting { } } + const containerList = getListByPosition(position, precedingToken.parent); + // use list position if the preceding token is before any list items + if (containerList && !rangeContainsRange(containerList, precedingToken)) { + return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize; + } + return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options); } @@ -394,6 +400,13 @@ namespace ts.formatting { } } + function getActualIndentationForListStartLine(list: NodeArray, sourceFile: SourceFile, options: EditorSettings): number { + if (!list) { + return Value.Unknown; + } + return findColumnForFirstNonWhitespaceCharacterInLine(sourceFile.getLineAndCharacterOfPosition(list.pos), sourceFile, options); + } + function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorSettings): number { const containingList = getContainingList(node, sourceFile); if (containingList) {