mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
block form indentation
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user