mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge pull request #12440 from atom/fb-serialize-panes-using-active-index
Serialize active pane item using index instead of URI
This commit is contained in:
@@ -1119,6 +1119,20 @@ describe "Pane", ->
|
||||
newPane = Pane.deserialize(pane.serialize(), atom)
|
||||
expect(newPane.getActiveItem()).toEqual newPane.itemAtIndex(1)
|
||||
|
||||
it "restores the active item when it doesn't implement getURI()", ->
|
||||
pane.items[1].getURI = null
|
||||
pane.activateItemAtIndex(1)
|
||||
newPane = Pane.deserialize(pane.serialize(), atom)
|
||||
expect(newPane.getActiveItem()).toEqual newPane.itemAtIndex(1)
|
||||
|
||||
it "restores the correct item when it doesn't implement getURI() and some items weren't deserialized", ->
|
||||
unserializable = {}
|
||||
pane.addItem(unserializable, {index: 0})
|
||||
pane.items[2].getURI = null
|
||||
pane.activateItemAtIndex(2)
|
||||
newPane = Pane.deserialize(pane.serialize(), atom)
|
||||
expect(newPane.getActiveItem()).toEqual newPane.itemAtIndex(1)
|
||||
|
||||
it "does not include items that cannot be deserialized", ->
|
||||
spyOn(console, 'warn')
|
||||
unserializable = {}
|
||||
|
||||
@@ -21,13 +21,16 @@ class Pane extends Model
|
||||
focused: false
|
||||
|
||||
@deserialize: (state, {deserializers, applicationDelegate, config, notifications}) ->
|
||||
{items, itemStackIndices, activeItemURI, activeItemUri} = state
|
||||
{items, itemStackIndices, activeItemIndex, activeItemURI, activeItemUri} = state
|
||||
activeItemURI ?= activeItemUri
|
||||
state.items = compact(items.map (itemState) -> deserializers.deserialize(itemState))
|
||||
state.activeItem = find state.items, (item) ->
|
||||
if typeof item.getURI is 'function'
|
||||
itemURI = item.getURI()
|
||||
itemURI is activeItemURI
|
||||
items = items.map (itemState) -> deserializers.deserialize(itemState)
|
||||
state.activeItem = items[activeItemIndex]
|
||||
state.items = compact(items)
|
||||
if activeItemURI?
|
||||
state.activeItem ?= find state.items, (item) ->
|
||||
if typeof item.getURI is 'function'
|
||||
itemURI = item.getURI()
|
||||
itemURI is activeItemURI
|
||||
new Pane(extend(state, {
|
||||
deserializerManager: deserializers,
|
||||
notificationManager: notifications,
|
||||
@@ -53,16 +56,15 @@ class Pane extends Model
|
||||
@setFlexScale(params?.flexScale ? 1)
|
||||
|
||||
serialize: ->
|
||||
if typeof @activeItem?.getURI is 'function'
|
||||
activeItemURI = @activeItem.getURI()
|
||||
itemsToBeSerialized = compact(@items.map((item) -> item if typeof item.serialize is 'function'))
|
||||
itemStackIndices = (itemsToBeSerialized.indexOf(item) for item in @itemStack when typeof item.serialize is 'function')
|
||||
activeItemIndex = itemsToBeSerialized.indexOf(@activeItem)
|
||||
|
||||
deserializer: 'Pane'
|
||||
id: @id
|
||||
items: itemsToBeSerialized.map((item) -> item.serialize())
|
||||
itemStackIndices: itemStackIndices
|
||||
activeItemURI: activeItemURI
|
||||
activeItemIndex: activeItemIndex
|
||||
focused: @focused
|
||||
flexScale: @flexScale
|
||||
|
||||
|
||||
Reference in New Issue
Block a user