supressFormatOnKeyInComments

This commit is contained in:
Arthur Ozga 2017-08-07 15:45:56 -07:00
parent 777bc575ac
commit 091376f46f
2 changed files with 19 additions and 16 deletions

View file

@ -31,6 +31,11 @@ namespace ts.formatting {
return 0;
}
const indentationOfEnclosingMultiLineComment = getIndentationOfEnclosingMultiLineComment(sourceFile, position, options);
if (indentationOfEnclosingMultiLineComment >= 0) {
return indentationOfEnclosingMultiLineComment;
}
const precedingToken = findPrecedingToken(position, sourceFile);
if (!precedingToken) {
return getBaseIndentation(options);
@ -44,11 +49,6 @@ namespace ts.formatting {
const lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
const indentationOfEnclosingMultiLineComment = getIndentationOfEnclosingMultiLineComment(sourceFile, position, options);
if (indentationOfEnclosingMultiLineComment >= 0) {
return indentationOfEnclosingMultiLineComment;
}
// indentation is first non-whitespace character in a previous line
// for block indentation, we should look for a line which contains something that's not
// whitespace.

View file

@ -1757,17 +1757,20 @@ namespace ts {
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[] {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
const settings = toEditorSettings(options);
if (key === "{") {
return formatting.formatOnOpeningCurly(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "}") {
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
if (!isInComment(sourceFile, position)) {
if (key === "{") {
return formatting.formatOnOpeningCurly(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "}") {
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
}
}
return [];