Buffer.save only writes to disk if the buffer is modified

This prevents autosave from writing unmodified buffers to disk, which
was causing the tree view to rebuild directory contents based on the
write event just when switching tabs.
This commit is contained in:
Nathan Sobo
2013-01-02 04:12:14 -07:00
parent cb4d2f63ad
commit bb710d0ae0
2 changed files with 3 additions and 1 deletions

View File

@@ -337,6 +337,7 @@ describe 'Buffer', ->
filePath = '/tmp/temp.txt'
fs.write(filePath, "")
saveBuffer = new Buffer filePath
saveBuffer.setText("blah")
it "saves the contents of the buffer to the path", ->
saveBuffer.setText 'Buffer contents!'
@@ -370,6 +371,7 @@ describe 'Buffer', ->
describe "when the buffer has no path", ->
it "throws an exception", ->
saveBuffer = new Buffer
saveBuffer.setText "hi"
expect(-> saveBuffer.save()).toThrow()
describe "reload()", ->

View File

@@ -238,7 +238,7 @@ class Buffer
@undoManager.redo(editSession)
save: ->
@saveAs(@getPath())
@saveAs(@getPath()) if @isModified()
saveAs: (path) ->
unless path then throw new Error("Can't save buffer with no file path")