From a6c89b75fcf8a0c8dbcd5a48820ea87bc014dc62 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 29 Apr 2013 14:48:06 -0700 Subject: [PATCH] Retain command panel text between toggles Previously the mini editor was cleared on toggle but now the existing text retained and selected when toggled. --- .../command-panel/lib/command-panel-view.coffee | 10 ++++++---- .../command-panel/spec/command-panel-spec.coffee | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/packages/command-panel/lib/command-panel-view.coffee b/src/packages/command-panel/lib/command-panel-view.coffee index 38a0dc82f..aa75656aa 100644 --- a/src/packages/command-panel/lib/command-panel-view.coffee +++ b/src/packages/command-panel/lib/command-panel-view.coffee @@ -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() diff --git a/src/packages/command-panel/spec/command-panel-spec.coffee b/src/packages/command-panel/spec/command-panel-spec.coffee index 8114d0aef..1d597dda0 100644 --- a/src/packages/command-panel/spec/command-panel-spec.coffee +++ b/src/packages/command-panel/spec/command-panel-spec.coffee @@ -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()