From bb710d0ae0bc82beb68646fa823ef3e3c3eebf05 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 2 Jan 2013 04:12:14 -0700 Subject: [PATCH] `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. --- spec/app/buffer-spec.coffee | 2 ++ src/app/buffer.coffee | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/app/buffer-spec.coffee b/spec/app/buffer-spec.coffee index c19b336fa..ccfbd3dd4 100644 --- a/spec/app/buffer-spec.coffee +++ b/spec/app/buffer-spec.coffee @@ -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()", -> diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index 528caa2e6..5f8bc4182 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -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")