When showing an item on a pane, add it to the items list if needed

This commit is contained in:
Nathan Sobo
2013-02-18 15:38:43 -07:00
committed by probablycorey
parent 41f18ee6a2
commit d89a7eb522
2 changed files with 16 additions and 0 deletions

View File

@@ -24,6 +24,16 @@ describe "Pane", ->
expect(view2.css('display')).toBe ''
expect(pane.currentItem).toBe view2
describe "when the given item isn't yet in the items list on the pane", ->
it "adds it to the items list after the current item", ->
view3 = $$ -> @div id: 'view-3', "View 3"
pane.showItem(editSession1)
expect(pane.getCurrentItemIndex()).toBe 1
pane.showItem(view3)
expect(pane.getItems()).toEqual [view1, editSession1, view3, view2, editSession2]
expect(pane.currentItem).toBe view3
expect(pane.getCurrentItemIndex()).toBe 2
describe "when showing a model item", ->
describe "when no view has yet been appended for that item", ->
it "appends and shows a view to display the item based on its `.getViewClass` method", ->

View File

@@ -47,6 +47,7 @@ class Pane extends View
@showItem(@items[index])
showItem: (item) ->
@addItem(item)
@itemViews.children().hide()
view = @viewForItem(item)
unless view.parent().is(@itemViews)
@@ -54,6 +55,11 @@ class Pane extends View
@currentItem = item
view.show()
addItem: (item) ->
return if _.include(@items, item)
@items.splice(@getCurrentItemIndex() + 1, 0, item)
item
removeItem: (item) ->
@showNextItem() if item is @currentItem and @items.length > 1
_.remove(@items, item)