diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index b3a341f58..494dbc91a 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -132,6 +132,16 @@ describe "Pane", -> expect(-> pane.addItem('foo')).toThrow() expect(-> pane.addItem(1)).toThrow() + it "destroys any existing pending item if the new item is pending", -> + pane = new Pane(paneParams(items: [])) + itemA = new Item("A") + itemB = new Item("B") + itemA.pending = true + itemB.pending = true + pane.addItem(itemA) + pane.addItem(itemB) + expect(itemA.isDestroyed()).toBe true + describe "::activateItem(item)", -> pane = null @@ -155,7 +165,7 @@ describe "Pane", -> pane.activateItem(pane.itemAtIndex(1)) expect(observed).toEqual [pane.itemAtIndex(1)] - describe "activating pending items", -> + describe "when the item being activated is pending", -> itemC = null itemD = null @@ -164,24 +174,18 @@ describe "Pane", -> itemD = new Item("D") itemC.pending = true itemD.pending = true + + it "replaces the active item if it is pending", -> pane.activateItem(itemC) - - it "opens pending item", -> - expect(pane.getItems().length).toBe 3 - expect(pane.getActiveItem()).toBe pane.itemAtIndex(1) - - it "replaces original pending item when activating another pending item", -> + expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'C', 'B'] pane.activateItem(itemD) + expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'D', 'B'] - expect(pane.getItems().length).toBe 3 - expect(pane.getActiveItem()).toBe itemD - expect(pane.getActiveItem()).toBe pane.itemAtIndex(1) - - it "keeps pending item when non-pending item is activated", -> - pane.activateItem(pane.itemAtIndex(0)) - - expect(pane.getItems().length).toBe 3 - expect(pane.getActiveItem()).toBe pane.itemAtIndex(0) + it "adds the item after the active item if it is not pending", -> + pane.activateItem(itemC) + pane.activateItemAtIndex(2) + pane.activateItem(itemD) + expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'B', 'D'] describe "::activateNextItem() and ::activatePreviousItem()", -> it "sets the active item to the next/previous item, looping around at either end", -> diff --git a/src/pane.coffee b/src/pane.coffee index 3161a33ac..239e0eeff 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -365,6 +365,12 @@ class Pane extends Model return if item in @items + if item.isPending?() + for existingItem, i in @items + if existingItem.isPending?() + @destroyItem(existingItem) + break + if typeof item.onDidDestroy is 'function' @itemSubscriptions.set item, item.onDidDestroy => @removeItem(item, false)