mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
recompute character to column when comparing indentations
This commit is contained in:
1 parent
0952e7d8d6
commit
4c8cdb41e6
3 files changed
+46
-1
No files matched your search
@@ -886,12 +886,25 @@ namespace ts.formatting {
|
||||
else {
|
||||
const tokenStart = sourceFile.getLineAndCharacterOfPosition(pos);
|
||||
const startLinePosition = getStartPositionOfLine(tokenStart.line, sourceFile);
|
||||
if (indentation !== tokenStart.character || indentationIsDifferent(indentationString, startLinePosition)) {
|
||||
if (indentation !== characterToColumn(startLinePosition, tokenStart.character) || indentationIsDifferent(indentationString, startLinePosition)) {
|
||||
recordReplace(startLinePosition, tokenStart.character, indentationString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function characterToColumn(startLinePosition: number, characterInLine: number): number {
|
||||
let column = 0;
|
||||
for (let i = 0; i < characterInLine; i++) {
|
||||
if (sourceFile.text.charCodeAt(startLinePosition + i) === CharacterCodes.tab) {
|
||||
column += options.tabSize - column % options.tabSize;
|
||||
}
|
||||
else {
|
||||
column++;
|
||||
}
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
function indentationIsDifferent(indentationString: string, startLinePosition: number): boolean {
|
||||
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user