Project doesn't serialize non-modified buffers that don't exist on disk

This commit is contained in:
probablycorey
2013-12-09 11:41:57 -08:00
parent 63e3be8630
commit ec3e139632
2 changed files with 16 additions and 0 deletions

View File

@@ -26,6 +26,18 @@ describe "Project", ->
expect(deserializedProject.getBuffers().length).toBe 0
expect(atom.project.getBuffers().length).toBe 0
it "destroys non-existent non-modified buffers and does not include them in the serialized state", ->
nonExistentNonModified = atom.project.openSync("non-existent-non-modified.txt")
nonExistentModified = atom.project.openSync("non-existent-modified.txt")
nonExistentModified.setText("I am modified")
expect(atom.project.getBuffers().length).toBe 2
atom.project.getState().serializeForPersistence()
deserializedProject = atom.replicate().get('project')
expect(deserializedProject.getBuffers().length).toBe 1
expect(atom.project.getBuffers().length).toBe 1
it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", ->
atom.project.openSync('a')
expect(atom.project.getBuffers().length).toBe 1

View File

@@ -43,6 +43,7 @@ class Project extends telepath.Model
# Private: Called by telepath.
beforePersistence: ->
@destroyUnretainedBuffers()
@destroyNonExistentNonModified()
# Public: Register an opener for project files.
#
@@ -77,6 +78,9 @@ class Project extends telepath.Model
destroyUnretainedBuffers: ->
buffer.destroy() for buffer in @getBuffers() when not buffer.isRetained()
destroyNonExistentNonModified: ->
buffer.destroy() for buffer in @getBuffers() when not buffer.isModified() and not buffer.file.exists()
# Public: Returns the {Git} repository if available.
getRepo: -> @repo