diff --git a/spec/app/pane-spec.coffee b/spec/app/pane-spec.coffee index 963ce359f..d263cff4b 100644 --- a/spec/app/pane-spec.coffee +++ b/spec/app/pane-spec.coffee @@ -99,6 +99,13 @@ describe "Pane", -> expect(pane.getItems()).toEqual [editSession1, view2] expect(pane.activeItem).toBe editSession1 + it "triggers 'pane:item-removed' with the item and its former index", -> + itemRemovedHandler = jasmine.createSpy("itemRemovedHandler") + pane.on 'pane:item-removed', itemRemovedHandler + pane.removeItem(editSession1) + expect(itemRemovedHandler).toHaveBeenCalled() + expect(itemRemovedHandler.argsForCall[0][1..2]).toEqual [editSession1, 1] + it "removes the pane when its last item is removed", -> pane.removeItem(item) for item in pane.getItems() expect(pane.hasParent()).toBeFalsy() diff --git a/src/app/pane.coffee b/src/app/pane.coffee index 547160157..eadccaa50 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -94,10 +94,14 @@ class Pane extends View false removeItem: (item) -> + index = @items.indexOf(item) + return if index == -1 + @showNextItem() if item is @activeItem and @items.length > 1 _.remove(@items, item) item.destroy?() @cleanupItemView(item) + @trigger 'pane:item-removed', [item, index] @remove() unless @items.length itemForPath: (path) ->