mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
commit
81530761ba
@ -57,13 +57,23 @@ describe 'Buffer', ->
|
||||
path = "/tmp/tmp.txt"
|
||||
fs.write(path, "first")
|
||||
buffer.destroy()
|
||||
buffer = new Buffer(path)
|
||||
|
||||
afterEach ->
|
||||
fs.remove(path)
|
||||
|
||||
it "does not trigger a contents-change event when Atom modifies the file", ->
|
||||
buffer.insert([0,0], "HELLO!")
|
||||
changeHandler = jasmine.createSpy("buffer changed")
|
||||
buffer.on "change", changeHandler
|
||||
buffer.save()
|
||||
|
||||
waits 30
|
||||
runs ->
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "when the buffer is unmodified", ->
|
||||
it "triggers 'change' event and buffer remains unmodified", ->
|
||||
buffer = new Buffer(path)
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
buffer.on 'change', changeHandler
|
||||
fs.write(path, "second")
|
||||
|
@ -172,6 +172,7 @@ class Buffer
|
||||
|
||||
@trigger 'before-save'
|
||||
fs.write path, @getText()
|
||||
@file?.updateMd5()
|
||||
@modified = false
|
||||
@setPath(path)
|
||||
@trigger 'after-save'
|
||||
|
@ -5,7 +5,11 @@ _ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class File
|
||||
path: null
|
||||
md5: null
|
||||
|
||||
constructor: (@path) ->
|
||||
@updateMd5()
|
||||
|
||||
getPath: ->
|
||||
@path
|
||||
@ -13,6 +17,9 @@ class File
|
||||
getName: ->
|
||||
fs.base(@path)
|
||||
|
||||
updateMd5: ->
|
||||
@md5 = fs.md5ForPath(@path)
|
||||
|
||||
afterSubscribe: ->
|
||||
@subscribeToNativeChangeEvents() if @subscriptionCount() == 1
|
||||
|
||||
@ -21,7 +28,10 @@ class File
|
||||
|
||||
subscribeToNativeChangeEvents: ->
|
||||
@watchId = $native.watchPath @path, (eventTypes) =>
|
||||
@trigger 'contents-change' if eventTypes.modified?
|
||||
newMd5 = fs.md5ForPath(@getPath())
|
||||
if eventTypes.modified? and newMd5 != @md5
|
||||
@md5 = newMd5
|
||||
@trigger 'contents-change'
|
||||
|
||||
unsubscribeFromNativeChangeEvents: ->
|
||||
$native.unwatchPath(@path, @watchId)
|
||||
|
Loading…
Reference in New Issue
Block a user