From 091376f46ff928feb79b6faee3dd1b88804fd336 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 7 Aug 2017 15:45:56 -0700 Subject: [PATCH] supressFormatOnKeyInComments --- src/services/formatting/smartIndenter.ts | 10 +++++----- src/services/services.ts | 25 +++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index d0651ce140f..b0d58ddad12 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -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. diff --git a/src/services/services.ts b/src/services/services.ts index d6310258885..5a70ccca501 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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 [];