Merge pull request #4103 from atom/ns-fix-active-pane-deserialization

Make deserialization of the active pane more tolerant and add assertions to catch invalid states
This commit is contained in:
Nathan Sobo 2014-11-07 16:00:40 -07:00
commit 5193fa698f
3 changed files with 14 additions and 0 deletions

View File

@ -33,6 +33,13 @@ describe "PaneContainer", ->
[pane1B, pane2B, pane3B] = containerB.getPanes()
expect(containerB.getActivePane()).toBe pane3B
it "makes the first pane active if no pane exists for the activePaneId", ->
pane3A.activate()
state = containerA.serialize()
state.activePaneId = -22
containerB = atom.deserializers.deserialize(state)
expect(containerB.getActivePane()).toBe containerB.getPanes()[0]
it "does not allow the root pane to be destroyed", ->
container = new PaneContainer
container.getRoot().destroy()

View File

@ -40,6 +40,8 @@ class PaneContainer extends Model
@registerViewProviders()
@setRoot(params?.root ? new Pane)
@setActivePane(@getPanes()[0]) unless @getActivePane()
@destroyEmptyPanes() if params?.destroyEmptyPanes
@monitorActivePaneItem()
@ -137,6 +139,9 @@ class PaneContainer extends Model
setActivePane: (activePane) ->
if activePane isnt @activePane
unless activePane in @getPanes()
throw new Error("Setting active pane that is not present in pane container")
@activePane = activePane
@emitter.emit 'did-change-active-pane', @activePane
@activePane

View File

@ -502,6 +502,8 @@ class Pane extends Model
# Public: Makes this pane the *active* pane, causing it to gain focus.
activate: ->
throw new Error("Pane has been destroyed") if @isDestroyed()
@container?.setActivePane(this)
@emit 'activated'
@emitter.emit 'did-activate'