Skip to content

Commit 091376f

Browse files
committed
supressFormatOnKeyInComments
1 parent 777bc57 commit 091376f

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

src/services/formatting/smartIndenter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ namespace ts.formatting {
3131
return 0;
3232
}
3333

34+
const indentationOfEnclosingMultiLineComment = getIndentationOfEnclosingMultiLineComment(sourceFile, position, options);
35+
if (indentationOfEnclosingMultiLineComment >= 0) {
36+
return indentationOfEnclosingMultiLineComment;
37+
}
38+
3439
const precedingToken = findPrecedingToken(position, sourceFile);
3540
if (!precedingToken) {
3641
return getBaseIndentation(options);
@@ -44,11 +49,6 @@ namespace ts.formatting {
4449

4550
const lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
4651

47-
const indentationOfEnclosingMultiLineComment = getIndentationOfEnclosingMultiLineComment(sourceFile, position, options);
48-
if (indentationOfEnclosingMultiLineComment >= 0) {
49-
return indentationOfEnclosingMultiLineComment;
50-
}
51-
5252
// indentation is first non-whitespace character in a previous line
5353
// for block indentation, we should look for a line which contains something that's not
5454
// whitespace.

src/services/services.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,17 +1757,20 @@ namespace ts {
17571757
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[] {
17581758
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
17591759
const settings = toEditorSettings(options);
1760-
if (key === "{") {
1761-
return formatting.formatOnOpeningCurly(position, sourceFile, getRuleProvider(settings), settings);
1762-
}
1763-
else if (key === "}") {
1764-
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
1765-
}
1766-
else if (key === ";") {
1767-
return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
1768-
}
1769-
else if (key === "\n") {
1770-
return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
1760+
1761+
if (!isInComment(sourceFile, position)) {
1762+
if (key === "{") {
1763+
return formatting.formatOnOpeningCurly(position, sourceFile, getRuleProvider(settings), settings);
1764+
}
1765+
else if (key === "}") {
1766+
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
1767+
}
1768+
else if (key === ";") {
1769+
return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
1770+
}
1771+
else if (key === "\n") {
1772+
return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
1773+
}
17711774
}
17721775

17731776
return [];

0 commit comments

Comments
 (0)