diff --git a/src/packages/command-panel/lib/command-panel-view.coffee b/src/packages/command-panel/lib/command-panel-view.coffee index aa75656aa..188b1f3db 100644 --- a/src/packages/command-panel/lib/command-panel-view.coffee +++ b/src/packages/command-panel/lib/command-panel-view.coffee @@ -42,7 +42,7 @@ class CommandPanelView extends View @subscribeToCommand rootView, 'command-panel:toggle', => @toggle() @subscribeToCommand rootView, 'command-panel:toggle-preview', => @togglePreview() - @subscribeToCommand rootView, 'command-panel:find-in-file', => @attach('/') + @subscribeToCommand rootView, 'command-panel:find-in-file', => @findInFile() @subscribeToCommand rootView, 'command-panel:find-in-project', => @attach('Xx/') @subscribeToCommand rootView, 'command-panel:repeat-relative-address', => @repeatRelativeAddress() @subscribeToCommand rootView, 'command-panel:repeat-relative-address-in-reverse', => @repeatRelativeAddress(reverse: true) @@ -116,6 +116,13 @@ class CommandPanelView extends View @previewHeader.hide() super + findInFile: -> + if @miniEditor.getText()[0] is '/' + @attach() + @miniEditor.setSelectedBufferRange([[0, 1], [0, Infinity]]) + else + @attach('/') + escapedCommand: -> @miniEditor.getText() diff --git a/src/packages/command-panel/spec/command-panel-spec.coffee b/src/packages/command-panel/spec/command-panel-spec.coffee index 1d597dda0..892790c2b 100644 --- a/src/packages/command-panel/spec/command-panel-spec.coffee +++ b/src/packages/command-panel/spec/command-panel-spec.coffee @@ -299,16 +299,29 @@ describe "CommandPanel", -> expect(commandInterpreter.lastRelativeAddress.subcommands[0].regex.toString()).toEqual "/\\(items\\)/i" describe "when command-panel:find-in-file is triggered on an editor", -> - it "pre-populates the command panel's editor with / and moves the cursor to the last column", -> - spyOn(commandPanel, 'attach').andCallThrough() - commandPanel.miniEditor.setText("foo") - commandPanel.miniEditor.setCursorBufferPosition([0, 0]) + describe "when the command panel's editor does not begin with /", -> + it "pre-populates the command panel's editor with / and moves the cursor to the last column", -> + spyOn(commandPanel, 'attach').andCallThrough() + commandPanel.miniEditor.setText("foo") + commandPanel.miniEditor.setCursorBufferPosition([0, 0]) - rootView.getActiveView().trigger "command-panel:find-in-file" - expect(commandPanel.attach).toHaveBeenCalled() - expect(commandPanel.parent).not.toBeEmpty() - expect(commandPanel.miniEditor.getText()).toBe "/" - expect(commandPanel.miniEditor.getCursorBufferPosition()).toEqual [0, 1] + rootView.getActiveView().trigger "command-panel:find-in-file" + expect(commandPanel.attach).toHaveBeenCalled() + expect(commandPanel.parent).not.toBeEmpty() + expect(commandPanel.miniEditor.getText()).toBe "/" + expect(commandPanel.miniEditor.getCursorBufferPosition()).toEqual [0, 1] + + describe "when the command panel's editor begins with /", -> + it "selects text text after the /", -> + spyOn(commandPanel, 'attach').andCallThrough() + commandPanel.miniEditor.setText("/foo") + commandPanel.miniEditor.setCursorBufferPosition([0, 0]) + + rootView.getActiveView().trigger "command-panel:find-in-file" + expect(commandPanel.attach).toHaveBeenCalled() + expect(commandPanel.parent).not.toBeEmpty() + expect(commandPanel.miniEditor.getText()).toBe "/foo" + expect(commandPanel.miniEditor.getSelectedText()).toBe "foo" describe "when command-panel:find-in-project is triggered on the root view", -> it "pre-populates the command panel's editor with Xx/ and moves the cursor to the last column", ->