Editor emits buffer-changed-event

This commit is contained in:
Corey Johnson 2012-03-30 15:14:59 -07:00
parent 001d866bec
commit abb585fbf6
2 changed files with 33 additions and 0 deletions

View File

@ -1863,3 +1863,34 @@ describe "Editor", ->
expect(editor.lines.find('.line:eq(13)').text()).toBe 'A'
expect(editor.lines.find('.line:eq(14)').text()).toBe 'B'
expect(editor.lines.find('.line:eq(15)')).not.toExist()
describe "path-change event", ->
it "emits event when buffer's path is changed", ->
editor = new Editor()
eventHandler = jasmine.createSpy('eventHandler')
editor.on 'buffer-path-change', eventHandler
editor.buffer.setPath("moo.text")
it "emits event when editor receives a new buffer", ->
eventHandler = jasmine.createSpy('eventHandler')
editor.on 'buffer-path-change', eventHandler
editor.setBuffer(new Buffer("something.txt"))
expect(eventHandler).toHaveBeenCalled()
it "stops listening to events on previously set buffers", ->
eventHandler = jasmine.createSpy('eventHandler')
oldBuffer = editor.buffer
editor.on 'buffer-path-change', eventHandler
editor.setBuffer(new Buffer("something.txt"))
expect(eventHandler).toHaveBeenCalled()
eventHandler.reset()
oldBuffer.setPath("bad.txt")
expect(eventHandler).not.toHaveBeenCalled()
eventHandler.reset()
editor.buffer.setPath("new.txt")
expect(eventHandler).toHaveBeenCalled()

View File

@ -217,6 +217,8 @@ class Editor extends View
@unsubscribeFromBuffer()
@buffer = buffer
@trigger 'buffer-path-change'
@buffer.on "path-change.editor#{@id}", => @trigger 'buffer-path-change'
document.title = @buffer.getPath()
@renderer = new Renderer(@buffer)