block form indentation

This commit is contained in:
SaschaNaz
2015-05-15 21:00:32 +09:00
parent 28c9ff1d84
commit b85d56b857
2 changed files with 29 additions and 1 deletions
+27 -1
View File
@@ -26,7 +26,7 @@ module ts.formatting {
precedingToken.kind === SyntaxKind.TemplateHead ||
precedingToken.kind === SyntaxKind.TemplateMiddle ||
precedingToken.kind === SyntaxKind.TemplateTail;
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
return 0;
}
@@ -110,6 +110,12 @@ module ts.formatting {
if (actualIndentation !== Value.Unknown) {
return actualIndentation + indentationDelta;
}
// check if current node is a block-form item - if yes, take indentation from it
actualIndentation = getActualIndentationForBlockFormItem(current, sourceFile, options);
if (actualIndentation !== Value.Unknown) {
return actualIndentation + indentationDelta;
}
}
parentStart = getParentStart(parent, current, sourceFile);
let parentAndChildShareLine =
@@ -277,6 +283,15 @@ module ts.formatting {
return undefined;
}
function getActualIndentationForBlockFormItem(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
if (isPassableBlockForm(node.kind)) {
let firstChild = node.getChildAt(0);
let lineAndCharacter = getStartLineAndCharacterForNode(firstChild, sourceFile);
return findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter, sourceFile, options);
}
return Value.Unknown;
}
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
let containingList = getContainingList(node, sourceFile);
return containingList ? getActualIndentationFromList(containingList) : Value.Unknown;
@@ -400,5 +415,16 @@ module ts.formatting {
return false;
}
}
export function isPassableBlockForm(kind: SyntaxKind): boolean {
switch (kind) {
case SyntaxKind.ArrowFunction:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.ObjectLiteralExpression:
return true;
}
return false;
}
}
}
@@ -17,6 +17,8 @@ goTo.marker('1');
edit.insertLine('');
goTo.marker('2');
verify.currentLineContentIs(' ""');
edit.insertLine('');
verify.indentationIs(8);
goTo.marker('4');
edit.insertLine('');
goTo.marker('3');