diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts
index 58e3ed1b35..7931f1ea73 100644
--- a/src/services/formatting/formatting.ts
+++ b/src/services/formatting/formatting.ts
@@ -866,13 +866,17 @@ 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 {
+ return indentationString !== sourceFile.text.substr(startLinePosition , indentationString.length);
+ }
+
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
// split comment in lines
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
@@ -1152,4 +1156,4 @@ namespace ts.formatting {
return s;
}
}
-}
\ No newline at end of file
+}
diff --git a/tests/cases/fourslash/formattingReplaceSpacesWithTabs.ts b/tests/cases/fourslash/formattingReplaceSpacesWithTabs.ts
new file mode 100644
index 0000000000..37039c5a7a
--- /dev/null
+++ b/tests/cases/fourslash/formattingReplaceSpacesWithTabs.ts
@@ -0,0 +1,35 @@
+///
+
+////module Foo {
+/////*1*/class Test { }
+/////*2*/ class Test { }
+/////*3*/ class Test { }
+/////*4*/ class Test { }
+/////*5*/ class Test { }
+/////*6*/ class Test { }
+/////*7*/ class Test { }
+////}
+
+var options = format.copyFormatOptions();
+options.ConvertTabsToSpaces = false;
+var oldOptions = format.setFormatOptions(options);
+try {
+ format.document();
+ goTo.marker("1");
+ verify.currentLineContentIs("\tclass Test { }")
+ goTo.marker("2");
+ verify.currentLineContentIs("\tclass Test { }")
+ goTo.marker("3");
+ verify.currentLineContentIs("\tclass Test { }")
+ goTo.marker("4");
+ verify.currentLineContentIs("\tclass Test { }")
+ goTo.marker("5");
+ verify.currentLineContentIs("\tclass Test { }")
+ goTo.marker("6");
+ verify.currentLineContentIs("\tclass Test { }")
+ goTo.marker("7");
+ verify.currentLineContentIs("\tclass Test { }")
+}
+finally {
+ format.setFormatOptions(oldOptions);
+}
diff --git a/tests/cases/fourslash/formattingReplaceTabsWithSpaces.ts b/tests/cases/fourslash/formattingReplaceTabsWithSpaces.ts
new file mode 100644
index 0000000000..ad5b5508c4
--- /dev/null
+++ b/tests/cases/fourslash/formattingReplaceTabsWithSpaces.ts
@@ -0,0 +1,27 @@
+///
+
+////module Foo {
+/////*1*/ class Test { }
+/////*2*/ class Test { }
+/////*3*/class Test { }
+/////*4*/ class Test { }
+/////*5*/ class Test { }
+/////*6*/ class Test { }
+/////*7*/ class Test { }
+////}
+
+format.document();
+goTo.marker("1");
+verify.currentLineContentIs(" class Test { }")
+goTo.marker("2");
+verify.currentLineContentIs(" class Test { }")
+goTo.marker("3");
+verify.currentLineContentIs(" class Test { }")
+goTo.marker("4");
+verify.currentLineContentIs(" class Test { }")
+goTo.marker("5");
+verify.currentLineContentIs(" class Test { }")
+goTo.marker("6");
+verify.currentLineContentIs(" class Test { }")
+goTo.marker("7");
+verify.currentLineContentIs(" class Test { }")