mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Strip only trailing whitespace, not newlines. Also, strip *all* trailing whitespace, not just the first.
This commit is contained in:
@@ -7,7 +7,7 @@ describe "StripTrailingWhitespace", ->
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView
|
||||
StripTrailingWhitespace.initialize(rootView)
|
||||
StripTrailingWhitespace.activate(rootView)
|
||||
rootView.focus()
|
||||
editor = rootView.activeEditor()
|
||||
|
||||
@@ -15,9 +15,9 @@ describe "StripTrailingWhitespace", ->
|
||||
spyOn(fs, 'write')
|
||||
|
||||
# works for buffers that are already open when extension is initialized
|
||||
editor.insertText("foo ")
|
||||
editor.insertText("foo \nbar\t \n\nbaz")
|
||||
editor.buffer.saveAs("/tmp/test")
|
||||
expect(editor.buffer.getText()).toBe "foo"
|
||||
expect(editor.buffer.getText()).toBe "foo\nbar\n\nbaz"
|
||||
|
||||
# works for buffers that are opened after extension is initialized
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
@@ -25,4 +25,4 @@ describe "StripTrailingWhitespace", ->
|
||||
editor.insertText(" ")
|
||||
|
||||
editor.buffer.save()
|
||||
expect(editor.buffer.getText()).toBe 'Some text.'
|
||||
expect(editor.buffer.getText()).toBe 'Some text.\n'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports =
|
||||
initialize: (rootView) ->
|
||||
activate: (rootView) ->
|
||||
for buffer in rootView.project.buffers
|
||||
@stripTrailingWhitespaceBeforeSave(buffer)
|
||||
|
||||
@@ -8,5 +8,5 @@ module.exports =
|
||||
|
||||
stripTrailingWhitespaceBeforeSave: (buffer) ->
|
||||
buffer.on 'before-save', ->
|
||||
buffer.scan /\s+$/, (match, range, { replace }) ->
|
||||
buffer.scan /[ \t]+$/g, (match, range, { replace }) ->
|
||||
replace('')
|
||||
|
||||
Reference in New Issue
Block a user