mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
Buffer stores a is modified on disk flag
This commit is contained in:
parent
5f1e441538
commit
611eb93219
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user