mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Restore previous selections after tailing newlines are added
Closes #496
This commit is contained in:
committed by
Corey Johnson
parent
f21571eab1
commit
ca49d0714c
@@ -1,11 +1,12 @@
|
||||
module.exports =
|
||||
activate: ->
|
||||
rootView.eachBuffer (buffer) => @whitespaceBeforeSave(buffer)
|
||||
rootView.eachEditSession (editSession) => @whitespaceBeforeSave(editSession)
|
||||
|
||||
configDefaults:
|
||||
ensureSingleTrailingNewline: true
|
||||
|
||||
whitespaceBeforeSave: (buffer) ->
|
||||
whitespaceBeforeSave: (editSession) ->
|
||||
buffer = editSession.buffer
|
||||
buffer.on 'will-be-saved', ->
|
||||
buffer.transact ->
|
||||
buffer.scan /[ \t]+$/g, ({replace}) -> replace('')
|
||||
@@ -16,4 +17,6 @@ module.exports =
|
||||
while row and buffer.lineForRow(row) is ''
|
||||
buffer.deleteRow(row--)
|
||||
else
|
||||
selectedBufferRanges = editSession.getSelectedBufferRanges()
|
||||
buffer.append('\n')
|
||||
editSession.setSelectedBufferRanges(selectedBufferRanges)
|
||||
|
||||
@@ -79,3 +79,10 @@ describe "Whitespace", ->
|
||||
editor.insertText "no trailing newline"
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getText()).toBe "no trailing newline"
|
||||
|
||||
it "does not move the cursor when the new line is added", ->
|
||||
editor.insertText "foo"
|
||||
expect(editor.getCursorBufferPosition()).toEqual([0,3])
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getText()).toBe "foo\n"
|
||||
expect(editor.getCursorBufferPosition()).toEqual([0,3])
|
||||
|
||||
Reference in New Issue
Block a user