Fix issues splitting panes with DOM events

* ::copyActiveItem guards against not having an active item
* The Pane constructor removes undefined items from params.items
This commit is contained in:
Nathan Sobo
2014-01-15 04:00:25 -07:00
parent fe7c5b4bc1
commit 44331d0ba6
2 changed files with 8 additions and 2 deletions

View File

@@ -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

View File

@@ -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.
#