Retain command panel text between toggles

Previously the mini editor was cleared on toggle but now
the existing text retained and selected when toggled.
This commit is contained in:
Kevin Sawicki
2013-04-29 14:48:06 -07:00
parent 15cf475d04
commit a6c89b75fc
2 changed files with 18 additions and 6 deletions

View File

@@ -98,17 +98,19 @@ class CommandPanelView extends View
@previewList.collapseAllPaths()
@previewList.focus()
attach: (text='', options={}) ->
attach: (text, options={}) ->
@errorMessages.hide()
focus = options.focus ? true
rootView.vertical.append(this)
@miniEditor.focus() if focus
@miniEditor.setText(text)
@miniEditor.setCursorBufferPosition([0, Infinity])
if text?
@miniEditor.setText(text)
@miniEditor.setCursorBufferPosition([0, Infinity])
else
@miniEditor.selectAll()
detach: ->
@miniEditor.setText('')
rootView.focus()
@previewList.hide()
@previewHeader.hide()

View File

@@ -76,7 +76,7 @@ describe "CommandPanel", ->
expect(rootView.focus).toHaveBeenCalled()
expect(rootViewCloseHandler).not.toHaveBeenCalled()
expect(commandPanel.hasParent()).toBeFalsy()
expect(commandPanel.miniEditor.getText()).toBe ''
expect(commandPanel.miniEditor.getText()).toBe 'command'
describe "when core:cancel is triggered on the command panel's mini editor", ->
it "detaches the command panel, focuses the RootView and does not bubble the core:cancel event", ->
@@ -91,7 +91,7 @@ describe "CommandPanel", ->
expect(rootView.focus).toHaveBeenCalled()
expect(rootViewCancelHandler).not.toHaveBeenCalled()
expect(commandPanel.hasParent()).toBeFalsy()
expect(commandPanel.miniEditor.getText()).toBe ''
expect(commandPanel.miniEditor.getText()).toBe 'command'
describe "when command-panel:toggle is triggered on the root view", ->
beforeEach ->
@@ -115,6 +115,16 @@ describe "CommandPanel", ->
expect(commandPanel.hasParent()).toBeTruthy()
expect(commandPanel.miniEditor.hiddenInput).toMatchSelector ':focus'
describe "when the command panel is opened a second time", ->
it "displays and selects the previously entered text", ->
commandPanel.miniEditor.setText('command1')
rootView.trigger 'command-panel:toggle'
expect(commandPanel.hasParent()).toBeFalsy()
rootView.trigger 'command-panel:toggle'
expect(commandPanel.hasParent()).toBeTruthy()
expect(commandPanel.miniEditor.getText()).toBe 'command1'
expect(commandPanel.miniEditor.getSelectedText()).toBe 'command1'
describe "when the command panel is not visible", ->
it "shows and focuses the command panel", ->
expect(commandPanel.hasParent()).toBeFalsy()