Skip to content

Commit de177d4

Browse files
committed
Merge pull request microsoft#8487 from ziacik/fix-space-tab-indentation
Fix space tab indentation
2 parents a715c45 + e11b08f commit de177d4

3 files changed

Lines changed: 69 additions & 3 deletions

File tree

src/services/formatting/formatting.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,13 +866,17 @@ 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+
return indentationString !== sourceFile.text.substr(startLinePosition , indentationString.length);
878+
}
879+
876880
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
877881
// split comment in lines
878882
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
@@ -1152,4 +1156,4 @@ namespace ts.formatting {
11521156
return s;
11531157
}
11541158
}
1155-
}
1159+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////module Foo {
4+
/////*1*/class Test { }
5+
/////*2*/ class Test { }
6+
/////*3*/ class Test { }
7+
/////*4*/ class Test { }
8+
/////*5*/ class Test { }
9+
/////*6*/ class Test { }
10+
/////*7*/ class Test { }
11+
////}
12+
13+
var options = format.copyFormatOptions();
14+
options.ConvertTabsToSpaces = false;
15+
var oldOptions = format.setFormatOptions(options);
16+
try {
17+
format.document();
18+
goTo.marker("1");
19+
verify.currentLineContentIs("\tclass Test { }")
20+
goTo.marker("2");
21+
verify.currentLineContentIs("\tclass Test { }")
22+
goTo.marker("3");
23+
verify.currentLineContentIs("\tclass Test { }")
24+
goTo.marker("4");
25+
verify.currentLineContentIs("\tclass Test { }")
26+
goTo.marker("5");
27+
verify.currentLineContentIs("\tclass Test { }")
28+
goTo.marker("6");
29+
verify.currentLineContentIs("\tclass Test { }")
30+
goTo.marker("7");
31+
verify.currentLineContentIs("\tclass Test { }")
32+
}
33+
finally {
34+
format.setFormatOptions(oldOptions);
35+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////module Foo {
4+
/////*1*/ class Test { }
5+
/////*2*/ class Test { }
6+
/////*3*/class Test { }
7+
/////*4*/ class Test { }
8+
/////*5*/ class Test { }
9+
/////*6*/ class Test { }
10+
/////*7*/ class Test { }
11+
////}
12+
13+
format.document();
14+
goTo.marker("1");
15+
verify.currentLineContentIs(" class Test { }")
16+
goTo.marker("2");
17+
verify.currentLineContentIs(" class Test { }")
18+
goTo.marker("3");
19+
verify.currentLineContentIs(" class Test { }")
20+
goTo.marker("4");
21+
verify.currentLineContentIs(" class Test { }")
22+
goTo.marker("5");
23+
verify.currentLineContentIs(" class Test { }")
24+
goTo.marker("6");
25+
verify.currentLineContentIs(" class Test { }")
26+
goTo.marker("7");
27+
verify.currentLineContentIs(" class Test { }")

0 commit comments

Comments
 (0)