Emit 'item-added' before setting the ::activeItem when adding first item

Fixes atom/tabs#11
This commit is contained in:
Nathan Sobo
2014-01-17 10:53:15 -07:00
parent 4f82662263
commit 926493f05c
2 changed files with 7 additions and 2 deletions

View File

@@ -44,11 +44,16 @@ describe "Pane", ->
pane.addItem(item4)
expect(pane.items).toEqual [item1, item2, item4, item3]
it "sets the active item if it is undefined", ->
it "sets the active item after adding the first item", ->
pane = new Pane
item = new Item("A")
events = []
pane.on 'item-added', -> events.push('item-added')
pane.$activeItem.changes.onValue -> events.push('active-item-changed')
pane.addItem(item)
expect(pane.activeItem).toBe item
expect(events).toEqual ['item-added', 'active-item-changed']
describe "::activateItem(item)", ->
pane = null

View File

@@ -132,8 +132,8 @@ class Pane extends Model
return if item in @items
@items.splice(index, 0, item)
@activeItem ?= item
@emit 'item-added', item, index
@activeItem ?= item
item
# Public: Adds the given items to the pane.