mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
When Buffer's path changes, stop listening for events on former path
This commit is contained in:
@@ -478,3 +478,23 @@ describe 'Buffer', ->
|
||||
expect(buffer.positionForCharacterIndex(30)).toEqual [1, 0]
|
||||
expect(buffer.positionForCharacterIndex(61)).toEqual [2, 0]
|
||||
expect(buffer.positionForCharacterIndex(408)).toEqual [12, 2]
|
||||
|
||||
describe ".setPath(path)", ->
|
||||
[path, newPath] = []
|
||||
beforeEach ->
|
||||
path = fs.join(require.resolve('fixtures'), "tmp.txt")
|
||||
fs.write(path, "first")
|
||||
|
||||
afterEach ->
|
||||
fs.remove(path)
|
||||
|
||||
it "stops listening to events on previous path and begins listening to events on new path", ->
|
||||
buffer = new Buffer(path)
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
buffer.on 'change', changeHandler
|
||||
buffer.setPath(filePath)
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
|
||||
fs.write(path, "should not trigger buffer event")
|
||||
waits 20
|
||||
runs -> expect(changeHandler).not.toHaveBeenCalled()
|
||||
|
||||
@@ -35,6 +35,7 @@ class Buffer
|
||||
null
|
||||
|
||||
setPath: (path) ->
|
||||
@file?.off()
|
||||
@file = new File(path)
|
||||
@file.on "contents-change", =>
|
||||
@setText(fs.read(@file.getPath())) unless @isModified()
|
||||
|
||||
Reference in New Issue
Block a user