Merge pull request #8487 from ziacik/fix-space-tab-indentation

Fix space tab indentation
This commit is contained in:
Mohamed Hegazy 2016-05-06 15:43:14 -07:00
commit de177d48d8
3 changed files with 69 additions and 3 deletions

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,35 @@
/// <reference path="fourslash.ts"/>
////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);
}

View file

@ -0,0 +1,27 @@
/// <reference path="fourslash.ts"/>
////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 { }")