Add eachBuffer helper to RootView

This allows extensions to bind a callback to all current
and future buffers.
This commit is contained in:
Kevin Sawicki
2012-10-12 09:16:46 -07:00
parent 24777da703
commit 220044c8bd
3 changed files with 39 additions and 10 deletions

View File

@@ -718,3 +718,31 @@ describe "RootView", ->
rootView.getActiveEditor().splitRight()
expect(count).toBe 1
expect(callbackEditor).toBe rootView.getActiveEditor()
describe ".eachBuffer(callback)", ->
beforeEach ->
rootView.attachToDom()
it "invokes the callback for existing buffer", ->
count = 0
callbackBuffer = null
callback = (buffer) ->
callbackBuffer = buffer
count++
rootView.eachBuffer(callback)
expect(count).toBe 1
expect(callbackBuffer).toBe rootView.getActiveEditor().getBuffer()
it "invokes the callback for new buffer", ->
count = 0
callbackBuffer = null
callback = (buffer) ->
callbackBuffer = buffer
count++
rootView.eachBuffer(callback)
count = 0
callbackBuffer = null
rootView.open(require.resolve('fixtures/sample.txt'))
expect(count).toBe 1
expect(callbackBuffer).toBe rootView.getActiveEditor().getBuffer()