Preserve focus state of command panel's mini-editor on refresh

This commit is contained in:
Nathan Sobo 2012-07-26 11:26:38 -06:00
parent 252a1a4d5f
commit dcc1193b49
2 changed files with 24 additions and 8 deletions

View File

@ -18,16 +18,29 @@ describe "CommandPanel", ->
rootView.deactivate()
describe "serialization", ->
it "preserves the command panel's mini editor text and visibility across reloads", ->
it "preserves the command panel's mini-editor text, visibility, and focus across reloads", ->
rootView.attachToDom()
rootView.trigger 'command-panel:toggle'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
commandPanel.miniEditor.insertText 'abc'
newRootView = RootView.deserialize(rootView.serialize())
rootView2 = RootView.deserialize(rootView.serialize())
rootView.deactivate()
rootView2.attachToDom()
commandPanel = newRootView.activateExtension(CommandPanel)
expect(newRootView.find('.command-panel')).toExist()
commandPanel = rootView2.activateExtension(CommandPanel)
expect(rootView2.find('.command-panel')).toExist()
expect(commandPanel.miniEditor.getText()).toBe 'abc'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
newRootView.remove()
rootView2.focus()
expect(commandPanel.miniEditor.isFocused).toBeFalsy()
rootView3 = RootView.deserialize(rootView2.serialize())
rootView2.deactivate()
rootView3.attachToDom()
commandPanel = rootView3.activateExtension(CommandPanel)
expect(commandPanel.miniEditor.isFocused).toBeFalsy()
rootView3.deactivate()
describe "when command-panel:close is triggered on the command panel", ->
it "detaches the command panel", ->

View File

@ -23,10 +23,12 @@ class CommandPanel extends View
@serialize: ->
text: @instance.miniEditor.getText()
visible: @instance.hasParent()
miniEditorFocused: @instance.miniEditor.isFocused
@deserialize: (state, rootView) ->
commandPanel = new CommandPanel(rootView)
commandPanel.attach(state.text) if state.visible
commandPanel.attach(state.text, focus: false) if state.visible
commandPanel.miniEditor.focus() if state.miniEditorFocused
commandPanel
@content: (rootView) ->
@ -85,9 +87,10 @@ class CommandPanel extends View
else
@miniEditor.focus()
attach: (text='') ->
attach: (text='', options={}) ->
focus = options.focus ? true
@rootView.vertical.append(this)
@miniEditor.focus()
@miniEditor.focus() if focus
@miniEditor.setText(text)
@miniEditor.setCursorBufferPosition([0, Infinity])