From 44331d0ba6fff8eb43ac0100901efe6a2b77e24a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 15 Jan 2014 04:00:25 -0700 Subject: [PATCH] Fix issues splitting panes with DOM events * ::copyActiveItem guards against not having an active item * The Pane constructor removes undefined items from params.items --- spec/pane-spec.coffee | 5 +++++ src/pane.coffee | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 667c64cf8..7d2c802fa 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -23,6 +23,11 @@ describe "Pane", -> pane = new Pane(items: [new Item("A"), new Item("B")]) expect(pane.activeItem).toBe pane.items[0] + it "compacts the items array", -> + pane = new Pane(items: [undefined, new Item("A"), null, new Item("B")]) + expect(pane.items.length).toBe 2 + expect(pane.activeItem).toBe pane.items[0] + describe "::activateItem(item)", -> pane = null diff --git a/src/pane.coffee b/src/pane.coffee index 0f48fb0cd..e42d9f97d 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -31,7 +31,7 @@ class Pane extends Model constructor: (params) -> super - @items = Sequence.fromArray(params?.items ? []) + @items = Sequence.fromArray(compact(params?.items ? [])) @activeItem ?= @items[0] @subscribe @items.onEach (item) => @@ -259,7 +259,8 @@ class Pane extends Model # Private: copyActiveItem: -> - @activeItem.copy?() ? atom.deserializers.deserialize(@activeItem.serialize()) + if @activeItem? + @activeItem.copy?() ? atom.deserializers.deserialize(@activeItem.serialize()) # Public: Creates a new pane to the left of the receiver. #