diff --git a/spec/app/pane-spec.coffee b/spec/app/pane-spec.coffee index 6d090371b..3921542ef 100644 --- a/spec/app/pane-spec.coffee +++ b/spec/app/pane-spec.coffee @@ -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", -> diff --git a/src/app/pane.coffee b/src/app/pane.coffee index f94779bd5..2d121f7ff 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -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)