From d89a7eb52241f56bad1886d6581feaba9c7b57b9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 18 Feb 2013 15:38:43 -0700 Subject: [PATCH] When showing an item on a pane, add it to the items list if needed --- spec/app/pane-spec.coffee | 10 ++++++++++ src/app/pane.coffee | 6 ++++++ 2 files changed, 16 insertions(+) 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)