From d4915b2a307e9b6ee5e650256674a8b8ac648103 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 4 Dec 2018 11:04:25 -0800 Subject: [PATCH] Revert over-eager bailout when trailing whitespace --- src/services/formatting/formatting.ts | 5 +---- tests/cases/fourslash/formatAfterWhitespace.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/formatAfterWhitespace.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index a5135f117831c..01c09a4989ce7 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1106,10 +1106,7 @@ namespace ts.formatting { * Trimming will be done for lines after the previous range */ function trimTrailingWhitespacesForRemainingRange() { - if (!previousRange) { - return; - } - const startPosition = previousRange.end; + const startPosition = previousRange ? previousRange.end : originalRange.pos; const startLine = sourceFile.getLineAndCharacterOfPosition(startPosition).line; const endLine = sourceFile.getLineAndCharacterOfPosition(originalRange.end).line; diff --git a/tests/cases/fourslash/formatAfterWhitespace.ts b/tests/cases/fourslash/formatAfterWhitespace.ts new file mode 100644 index 0000000000000..02e2c60b36e2b --- /dev/null +++ b/tests/cases/fourslash/formatAfterWhitespace.ts @@ -0,0 +1,14 @@ +/// +////function foo() +////{ +//// var bar; +//// /*1*/ +////} +goTo.marker('1') +edit.insertLine(""); +verify.currentFileContentIs(`function foo() +{ + var bar; + + +}`);