Skip to content

Commit 06d05b0

Browse files
committed
Fixes space-tab indentation issues
1 parent ba2a330 commit 06d05b0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/services/formatting/formatting.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,13 +866,23 @@ namespace ts.formatting {
866866
}
867867
else {
868868
let tokenStart = sourceFile.getLineAndCharacterOfPosition(pos);
869-
if (indentation !== tokenStart.character) {
870-
let startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile);
869+
let startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile);
870+
if (indentation !== tokenStart.character || indentationIsDifferent(indentationString, startLinePosition)) {
871871
recordReplace(startLinePosition, tokenStart.character, indentationString);
872872
}
873873
}
874874
}
875875

876+
function indentationIsDifferent(indentationString: string, startLinePosition: number): boolean {
877+
let size = indentationString.length;
878+
for (let i = 0; i < size; i++) {
879+
if (indentationString.charCodeAt(i) !== sourceFile.text.charCodeAt(startLinePosition + i)) {
880+
return true;
881+
}
882+
}
883+
return false;
884+
}
885+
876886
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
877887
// split comment in lines
878888
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
@@ -1152,4 +1162,4 @@ namespace ts.formatting {
11521162
return s;
11531163
}
11541164
}
1155-
}
1165+
}

0 commit comments

Comments
 (0)