diff --git a/lib/find-view.coffee b/lib/find-view.coffee index 11f8d309..ee5b7d99 100644 --- a/lib/find-view.coffee +++ b/lib/find-view.coffee @@ -128,6 +128,10 @@ class FindView extends View atom.workspaceView.command 'find-and-replace:replace-all', @replaceAll showFind: => + unless @findEditor.getText() + editorView = atom.workspaceView.getActiveView() + @findEditor.setText(editorView.getSelectedText()) if editorView + @attach() if not @hasParent() @findEditor.focus() @findEditor.selectAll() diff --git a/spec/find-view-spec.coffee b/spec/find-view-spec.coffee index 686df229..7d4bf29d 100644 --- a/spec/find-view-spec.coffee +++ b/spec/find-view-spec.coffee @@ -20,6 +20,19 @@ describe 'FindView', -> editor.trigger 'find-and-replace:show' expect(atom.workspaceView.find('.find-and-replace')).toExist() + it "populates the findEditor with selection when there is a selection", -> + editor.setSelectedBufferRange([[2, 8], [2, 13]]) + editor.trigger 'find-and-replace:show' + expect(atom.workspaceView.find('.find-and-replace')).toExist() + expect(findView.findEditor.getText()).toBe('items') + + findView.findEditor.setText('') + + editor.setSelectedBufferRange([[2, 14], [2, 20]]) + editor.trigger 'find-and-replace:show' + expect(atom.workspaceView.find('.find-and-replace')).toExist() + expect(findView.findEditor.getText()).toBe('length') + describe "when FindView's replace editor is visible", -> it "keeps the replace editor visible when find-and-replace:show is triggered", -> editor.trigger 'find-and-replace:show-replace'