Make Pane close the current item when handling 'core:close' event

This commit is contained in:
Nathan Sobo
2013-02-21 11:13:10 -07:00
committed by probablycorey
parent 11a702a2a6
commit bd8ec81b1e
2 changed files with 10 additions and 0 deletions

View File

@@ -91,6 +91,12 @@ describe "Pane", ->
pane.removeItem(editSession2)
expect(editSession2.destroyed).toBeTruthy()
describe "core:close", ->
it "removes the current item", ->
initialItemCount = pane.getItems().length
pane.trigger 'core:close'
expect(pane.getItems().length).toBe initialItemCount - 1
describe "pane:show-next-item and pane:show-previous-item", ->
it "advances forward/backward through the pane's items, looping around at either end", ->
expect(pane.currentItem).toBe view1

View File

@@ -20,6 +20,7 @@ class Pane extends View
@viewsByClassName = {}
@showItem(@items[0])
@command 'core:close', @removeCurrentItem
@command 'pane:show-next-item', @showNextItem
@command 'pane:show-previous-item', @showPreviousItem
@command 'pane:split-left', => @splitLeft()
@@ -65,6 +66,9 @@ class Pane extends View
@items.splice(@getCurrentItemIndex() + 1, 0, item)
item
removeCurrentItem: =>
@removeItem(@currentItem)
removeItem: (item) ->
@showNextItem() if item is @currentItem and @items.length > 1
_.remove(@items, item)