mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Properly serialize pane focus state
This commit is contained in:
16
spec/pane-container-model-spec.coffee
Normal file
16
spec/pane-container-model-spec.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
PaneContainerModel = require '../src/pane-container-model'
|
||||
PaneModel = require '../src/pane-model'
|
||||
|
||||
describe "PaneContainerModel", ->
|
||||
describe "serialization", ->
|
||||
it "preserves the focused pane across serialization", ->
|
||||
pane1A = new PaneModel
|
||||
containerA = new PaneContainerModel(root: pane1A)
|
||||
pane2A = pane1A.splitRight()
|
||||
pane3A = pane2A.splitDown()
|
||||
expect(pane3A.focused).toBe true
|
||||
|
||||
containerB = containerA.testSerialization()
|
||||
[pane1A, pane2A, pane3A] = containerB.getPanes()
|
||||
expect(pane3A.focusContext).toBe containerB.focusContext
|
||||
expect(pane3A.focused).toBe true
|
||||
@@ -16,7 +16,7 @@ class PaneAxisModel extends Model
|
||||
|
||||
@property 'focusContext'
|
||||
|
||||
constructor: ({@orientation, children}) ->
|
||||
constructor: ({@focusContext, @orientation, children}) ->
|
||||
@children = Sequence.fromArray(children ? [])
|
||||
|
||||
@subscribe @$focusContext, (focusContext) =>
|
||||
@@ -33,7 +33,8 @@ class PaneAxisModel extends Model
|
||||
@when @children.$length.becomesLessThan(1), 'destroy'
|
||||
|
||||
deserializeParams: (params) ->
|
||||
params.children = params.children.map (childState) -> atom.deserializers.deserialize(childState)
|
||||
{focusContext} = params
|
||||
params.children = params.children.map (childState) -> atom.deserializers.deserialize(childState, {focusContext})
|
||||
params
|
||||
|
||||
serializeParams: ->
|
||||
|
||||
@@ -20,7 +20,8 @@ class PaneContainerModel extends Model
|
||||
root.focusContext = @focusContext
|
||||
|
||||
deserializeParams: (params) ->
|
||||
params.root = atom.deserializers.deserialize(params.root)
|
||||
params.focusContext ?= new FocusContext
|
||||
params.root = atom.deserializers.deserialize(params.root, focusContext: params.focusContext)
|
||||
params
|
||||
|
||||
serializeParams: (params) ->
|
||||
|
||||
@@ -13,12 +13,13 @@ class PaneModel extends Model
|
||||
Focusable.includeInto(this)
|
||||
|
||||
@properties
|
||||
items: -> []
|
||||
activeItem: null
|
||||
|
||||
constructor: (params) ->
|
||||
super
|
||||
|
||||
@focus() if params?.focused
|
||||
|
||||
@items = Sequence.fromArray(params?.items ? [])
|
||||
@activeItem ?= @items[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user