From 2d813e95c3601b3e0150a119fa73bc01eac22abd Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 9 Dec 2013 10:58:44 -0800 Subject: [PATCH 1/3] Show the find editor on cmd-e --- lib/find.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/find.coffee b/lib/find.coffee index 686d3dc7..4f42c122 100644 --- a/lib/find.coffee +++ b/lib/find.coffee @@ -39,6 +39,11 @@ module.exports = @projectFindView.attach() @projectFindView.findInCurrentlySelectedDirectory($(e.target)) + atom.workspaceView.command 'find-and-replace:use-selection-as-find-pattern', => + return if @projectFindView.isOnDom() or @findView.isOnDom() + @projectFindView.detach() + @findView.showFind() + atom.workspaceView.command 'find-and-replace:show', => @projectFindView.detach() @findView.showFind() From 3a3af4a01b3191378ca089b233448099b542f0b5 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 9 Dec 2013 11:46:15 -0800 Subject: [PATCH 2/3] Populate the find editor with selected text When it's empty. We assume the user wants to search for the selected text. See #93 --- lib/find-view.coffee | 4 ++++ spec/find-view-spec.coffee | 13 +++++++++++++ 2 files changed, 17 insertions(+) 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' From cb2897ce6146c6a7b7ee891e43ee67ea00f70dac Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 9 Dec 2013 11:46:38 -0800 Subject: [PATCH 3/3] The project find view defaults to the selected text See #93 --- lib/project-find-view.coffee | 5 +++++ spec/project-find-view-spec.coffee | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/project-find-view.coffee b/lib/project-find-view.coffee index 67678ebc..472c73f0 100644 --- a/lib/project-find-view.coffee +++ b/lib/project-find-view.coffee @@ -116,6 +116,11 @@ class ProjectFindView extends View attach: -> atom.workspaceView.vertical.append(this) unless @hasParent() + + unless @findEditor.getText() + editorView = atom.workspaceView.getActiveView() + @findEditor.setText(editorView.getSelectedText()) if editorView + @findEditor.focus() @findEditor.selectAll() diff --git a/spec/project-find-view-spec.coffee b/spec/project-find-view-spec.coffee index d937f692..e6421f28 100644 --- a/spec/project-find-view-spec.coffee +++ b/spec/project-find-view-spec.coffee @@ -40,6 +40,25 @@ describe 'ProjectFindView', -> expect(projectFindView.find('.loading')).not.toBeVisible() expect(projectFindView.findEditor.getSelectedBufferRange()).toEqual [[0, 0], [0, 5]] + describe "with an open buffer", -> + beforeEach -> + projectFindView.findEditor.setText('') + atom.workspaceView.openSync('sample.js') + editor = atom.workspaceView.getActiveView() + + it "populates the findEditor with selection when there is a selection", -> + editor.setSelectedBufferRange([[2, 8], [2, 13]]) + atom.workspaceView.trigger 'project-find:show' + expect(atom.workspaceView.find('.project-find')).toExist() + expect(projectFindView.findEditor.getText()).toBe('items') + + projectFindView.findEditor.setText('') + + editor.setSelectedBufferRange([[2, 14], [2, 20]]) + atom.workspaceView.trigger 'project-find:show' + expect(atom.workspaceView.find('.project-find')).toExist() + expect(projectFindView.findEditor.getText()).toBe('length') + describe "when thethe ProjectFindView is already attached", -> beforeEach -> atom.workspaceView.trigger 'project-find:show'