Buffer stores a is modified on disk flag

This commit is contained in:
Corey Johnson 2012-07-16 16:11:52 -07:00
parent 5f1e441538
commit 611eb93219
2 changed files with 23 additions and 1 deletions

View File

@ -90,6 +90,21 @@ describe 'Buffer', ->
expect(event.newText).toBe "second"
expect(buffer.isModified()).toBeFalsy()
describe "when the buffer is modified", ->
it "sets modifiedOnDisk to be true", ->
fileChangeHandler = jasmine.createSpy('fileChange')
buffer.file.on 'contents-change', fileChangeHandler
buffer.insert([0, 0], "a change")
fs.write(path, "second")
expect(fileChangeHandler.callCount).toBe 0
waitsFor "file to trigger contents-change event", ->
fileChangeHandler.callCount > 0
runs ->
expect(buffer.isModifiedOnDisk()).toBeTruthy()
describe ".isModified()", ->
beforeEach ->
buffer.destroy()

View File

@ -12,6 +12,7 @@ class Buffer
@idCounter = 1
undoManager: null
modified: null
modifiedOnDisk: null
lines: null
file: null
@ -41,7 +42,9 @@ class Buffer
@file?.off()
@file = new File(path)
@file.on "contents-change", =>
unless @isModified()
if @isModified()
@modifiedOnDisk = true
else
@setText(fs.read(@file.getPath()))
@modified = false
@trigger "path-change", this
@ -167,9 +170,13 @@ class Buffer
fs.write path, @getText()
@file?.updateMd5()
@modified = false
@modifiedOnDisk = false
@setPath(path)
@trigger 'after-save'
isModifiedOnDisk: ->
@modifiedOnDisk
isModified: ->
@modified