Merge pull request #8487 from ziacik/fix-space-tab-indentation
Fix space tab indentation
This commit is contained in:
commit
de177d48d8
|
@ -866,13 +866,17 @@ namespace ts.formatting {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let tokenStart = sourceFile.getLineAndCharacterOfPosition(pos);
|
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);
|
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) {
|
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
|
||||||
// split comment in lines
|
// split comment in lines
|
||||||
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
|
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
|
||||||
|
@ -1152,4 +1156,4 @@ namespace ts.formatting {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
tests/cases/fourslash/formattingReplaceSpacesWithTabs.ts
Normal file
35
tests/cases/fourslash/formattingReplaceSpacesWithTabs.ts
Normal 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);
|
||||||
|
}
|
27
tests/cases/fourslash/formattingReplaceTabsWithSpaces.ts
Normal file
27
tests/cases/fourslash/formattingReplaceTabsWithSpaces.ts
Normal 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 { }")
|
Loading…
Reference in a new issue