From 06d05b079ef84744f52033d0d7d0cdde61e56334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20=C5=BDia=C4=8Dik?= Date: Thu, 5 May 2016 23:23:25 +0200 Subject: [PATCH] Fixes space-tab indentation issues --- src/services/formatting/formatting.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 58e3ed1b35..0388ba42b3 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -866,13 +866,23 @@ namespace ts.formatting { } else { let tokenStart = sourceFile.getLineAndCharacterOfPosition(pos); - if (indentation !== tokenStart.character) { - let startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile); + let startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile); + if (indentation !== tokenStart.character || indentationIsDifferent(indentationString, startLinePosition)) { recordReplace(startLinePosition, tokenStart.character, indentationString); } } } + function indentationIsDifferent(indentationString: string, startLinePosition: number): boolean { + let size = indentationString.length; + for (let i = 0; i < size; i++) { + if (indentationString.charCodeAt(i) !== sourceFile.text.charCodeAt(startLinePosition + i)) { + return true; + } + } + return false; + } + function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) { // split comment in lines let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; @@ -1152,4 +1162,4 @@ namespace ts.formatting { return s; } } -} \ No newline at end of file +}