mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
Fire 'modified-status-changed' events on changes after save/reload
Buffer keeps state about the value with which it fired the last modified-status-changed event so that it doesn't fire it twice with the same boolean value. Every piece of code that triggers the event also needs to set this state, so now everything goes through the `triggerModifiedStatusChanged` method.
This commit is contained in:
parent
699e780e99
commit
59a06acc0b
@ -181,7 +181,7 @@ describe 'Buffer', ->
|
||||
changeHandler.callCount > 0
|
||||
|
||||
describe "modified status", ->
|
||||
it "reports a modified status of true after the user changes buffer", ->
|
||||
it "reports the modified status changing to true or false after the user changes buffer", ->
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
@ -203,7 +203,7 @@ describe 'Buffer', ->
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(false)
|
||||
|
||||
it "reports a modified status of true after the underlying file is deleted", ->
|
||||
it "reports the modified status changing to true after the underlying file is deleted", ->
|
||||
buffer.release()
|
||||
filePath = "/tmp/atom-tmp-file"
|
||||
fs.write(filePath, 'delete me')
|
||||
@ -216,7 +216,7 @@ describe 'Buffer', ->
|
||||
waitsFor "modified status to change", -> modifiedHandler.callCount
|
||||
runs -> expect(buffer.isModified()).toBe true
|
||||
|
||||
it "reports a modified status of false after a modified buffer is saved", ->
|
||||
it "reports the modified status changing to false after a modified buffer is saved", ->
|
||||
filePath = "/tmp/atom-tmp-file"
|
||||
fs.write(filePath, '')
|
||||
buffer.release()
|
||||
@ -225,14 +225,22 @@ describe 'Buffer', ->
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
buffer.insert([0,0], "hi")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(buffer.isModified()).toBe true
|
||||
modifiedHandler.reset()
|
||||
|
||||
buffer.save()
|
||||
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(false)
|
||||
expect(buffer.isModified()).toBe false
|
||||
modifiedHandler.reset()
|
||||
|
||||
it "reports a modified status of false after a modified buffer is reloaded", ->
|
||||
buffer.insert([0, 0], 'x')
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(true)
|
||||
expect(buffer.isModified()).toBe true
|
||||
|
||||
it "reports the modified status changing to false after a modified buffer is reloaded", ->
|
||||
filePath = "/tmp/atom-tmp-file"
|
||||
fs.write(filePath, '')
|
||||
buffer.release()
|
||||
@ -241,12 +249,19 @@ describe 'Buffer', ->
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
buffer.insert([0,0], "hi")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(buffer.isModified()).toBe true
|
||||
modifiedHandler.reset()
|
||||
|
||||
buffer.reload()
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(false)
|
||||
expect(buffer.isModified()).toBe false
|
||||
modifiedHandler.reset()
|
||||
|
||||
buffer.insert([0, 0], 'x')
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(true)
|
||||
expect(buffer.isModified()).toBe true
|
||||
|
||||
it "returns false for an empty buffer with no path", ->
|
||||
buffer.release()
|
||||
|
@ -69,7 +69,7 @@ class Buffer
|
||||
|
||||
@file.on "removed", =>
|
||||
@updateCachedDiskContents()
|
||||
@trigger "modified-status-changed", @isModified()
|
||||
@triggerModifiedStatusChanged(@isModified())
|
||||
|
||||
@file.on "moved", =>
|
||||
@trigger "path-changed", this
|
||||
@ -78,7 +78,7 @@ class Buffer
|
||||
@trigger 'will-reload'
|
||||
@updateCachedDiskContents()
|
||||
@setText(@cachedDiskContents)
|
||||
@trigger 'modified-status-changed', false
|
||||
@triggerModifiedStatusChanged(false)
|
||||
@trigger 'reloaded'
|
||||
|
||||
updateCachedDiskContents: ->
|
||||
@ -253,7 +253,7 @@ class Buffer
|
||||
@setPath(path)
|
||||
@cachedDiskContents = @getText()
|
||||
@file.write(@getText())
|
||||
@trigger 'modified-status-changed', false
|
||||
@triggerModifiedStatusChanged(false)
|
||||
@trigger 'saved'
|
||||
|
||||
isModified: ->
|
||||
@ -432,11 +432,14 @@ class Buffer
|
||||
@stoppedChangingTimeout = null
|
||||
modifiedStatus = @isModified()
|
||||
@trigger 'contents-modified', modifiedStatus
|
||||
unless modifiedStatus is @previousModifiedStatus
|
||||
@previousModifiedStatus = modifiedStatus
|
||||
@trigger 'modified-status-changed', modifiedStatus
|
||||
@triggerModifiedStatusChanged(modifiedStatus)
|
||||
@stoppedChangingTimeout = setTimeout(stoppedChangingCallback, @stoppedChangingDelay)
|
||||
|
||||
triggerModifiedStatusChanged: (modifiedStatus) ->
|
||||
return if modifiedStatus is @previousModifiedStatus
|
||||
@previousModifiedStatus = modifiedStatus
|
||||
@trigger 'modified-status-changed', modifiedStatus
|
||||
|
||||
fileExists: ->
|
||||
@file.exists()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user