Only mark a deleted file as modified if it was previously modified.

Fixes #693
This commit is contained in:
probablycorey
2013-12-09 11:06:29 -08:00
parent b108b5030a
commit 63e3be8630
2 changed files with 33 additions and 28 deletions

View File

@@ -34,11 +34,11 @@ describe 'TextBuffer', ->
expect(buffer.getText()).toBe fs.readFileSync(filePath, 'utf8')
describe "when no file exists for the path", ->
it "is modified and is initially empty", ->
it "is not modified and is initially empty", ->
filePath = "does-not-exist.txt"
expect(fs.existsSync(filePath)).toBeFalsy()
buffer = atom.project.bufferForPathSync(filePath)
expect(buffer.isModified()).toBeTruthy()
expect(buffer.isModified()).not.toBeTruthy()
expect(buffer.getText()).toBe ''
describe "when no path is given", ->
@@ -160,20 +160,38 @@ describe 'TextBuffer', ->
filePath = bufferToDelete.getPath() # symlinks may have been converted
expect(bufferToDelete.getPath()).toBe filePath
expect(bufferToDelete.isModified()).toBeFalsy()
removeHandler = jasmine.createSpy('removeHandler')
bufferToDelete.file.on 'removed', removeHandler
fs.removeSync(filePath)
waitsFor "file to be removed", ->
removeHandler.callCount > 0
afterEach ->
bufferToDelete.destroy()
it "retains its path and reports the buffer as modified", ->
expect(bufferToDelete.getPath()).toBe filePath
expect(bufferToDelete.isModified()).toBeTruthy()
describe "when the file is modified", ->
beforeEach ->
bufferToDelete.setText("I WAS MODIFIED")
expect(bufferToDelete.isModified()).toBeTruthy()
removeHandler = jasmine.createSpy('removeHandler')
bufferToDelete.file.on 'removed', removeHandler
fs.removeSync(filePath)
waitsFor "file to be removed", ->
removeHandler.callCount > 0
it "retains its path and reports the buffer as modified", ->
expect(bufferToDelete.getPath()).toBe filePath
expect(bufferToDelete.isModified()).toBeTruthy()
describe "when the file is not modified", ->
beforeEach ->
expect(bufferToDelete.isModified()).toBeFalsy()
removeHandler = jasmine.createSpy('removeHandler')
bufferToDelete.file.on 'removed', removeHandler
fs.removeSync(filePath)
waitsFor "file to be removed", ->
removeHandler.callCount > 0
it "retains its path and reports the buffer as not modified", ->
expect(bufferToDelete.getPath()).toBe filePath
expect(bufferToDelete.isModified()).toBeFalsy()
it "resumes watching of the file when it is re-saved", ->
bufferToDelete.save()
@@ -210,19 +228,6 @@ describe 'TextBuffer', ->
advanceClock(buffer.stoppedChangingDelay)
expect(modifiedHandler).toHaveBeenCalledWith(false)
it "reports the modified status changing to true after the underlying file is deleted", ->
buffer.release()
filePath = path.join(temp.dir, 'atom-tmp-file')
fs.writeFileSync(filePath, 'delete me')
buffer = atom.project.bufferForPathSync(filePath)
modifiedHandler = jasmine.createSpy("modifiedHandler")
buffer.on 'modified-status-changed', modifiedHandler
fs.removeSync(filePath)
waitsFor "modified status to change", -> modifiedHandler.callCount
runs -> expect(buffer.isModified()).toBe true
it "reports the modified status changing to false after a modified buffer is saved", ->
filePath = path.join(temp.dir, 'atom-tmp-file')
fs.writeFileSync(filePath, '')

View File

@@ -117,8 +117,8 @@ class TextBuffer extends telepath.Model
@reload()
@file.on "removed", =>
@updateCachedDiskContents().done =>
@emitModifiedStatusChanged(@isModified())
@wasModifiedBeforeRemove = @getText() != @cachedDiskContents
@updateCachedDiskContents()
@file.on "moved", =>
@emit "path-changed", this
@@ -403,7 +403,7 @@ class TextBuffer extends telepath.Model
if @file.exists()
@getText() != @cachedDiskContents
else
true
@wasModifiedBeforeRemove ? not @isEmpty()
else
not @isEmpty()