Reuse search when re-toggling find in file

Previously the prior find in file search was thrown
away when toggling find-in-file subsequent times.

Now the previous search text is retained and selected when toggled.
This commit is contained in:
Kevin Sawicki
2013-04-29 15:16:45 -07:00
parent 9180060920
commit 16ffbd1920
2 changed files with 30 additions and 10 deletions

View File

@@ -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()

View File

@@ -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", ->