From 1956b989958da581e6d7ea1222f1bdabe963945c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sat, 29 Dec 2012 10:44:39 -0800 Subject: [PATCH] Don't strip newline when buffer is a single newline --- .../spec/strip-trailing-whitespace-spec.coffee | 5 +++++ .../src/strip-trailing-whitespace.coffee | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/packages/strip-trailing-whitespace/spec/strip-trailing-whitespace-spec.coffee b/src/packages/strip-trailing-whitespace/spec/strip-trailing-whitespace-spec.coffee index d55f2c1bd..9b5f7a304 100644 --- a/src/packages/strip-trailing-whitespace/spec/strip-trailing-whitespace-spec.coffee +++ b/src/packages/strip-trailing-whitespace/spec/strip-trailing-whitespace-spec.coffee @@ -64,3 +64,8 @@ describe "StripTrailingWhitespace", -> editor.insertText "" editor.save() expect(editor.getText()).toBe "" + + it "leaves a buffer that is a single newline untouched", -> + editor.insertText "\n" + editor.save() + expect(editor.getText()).toBe "\n" diff --git a/src/packages/strip-trailing-whitespace/src/strip-trailing-whitespace.coffee b/src/packages/strip-trailing-whitespace/src/strip-trailing-whitespace.coffee index 49a977b50..51f96f70a 100644 --- a/src/packages/strip-trailing-whitespace/src/strip-trailing-whitespace.coffee +++ b/src/packages/strip-trailing-whitespace/src/strip-trailing-whitespace.coffee @@ -15,8 +15,8 @@ module.exports = replace('') if config.get('stripTrailingWhitespace.singleTrailingNewline') if buffer.getLastLine() is '' - row = buffer.getLastRow() - while row and buffer.lineForRow(--row) is '' - buffer.deleteRow(row) + row = buffer.getLastRow() - 1 + while row and buffer.lineForRow(row) is '' + buffer.deleteRow(row--) else buffer.append('\n')