From 8aa9601c88380c49c9d01365be0d3fc1e786c951 Mon Sep 17 00:00:00 2001 From: liuderchi Date: Fri, 5 Aug 2016 17:12:10 +0800 Subject: [PATCH] :white_check_mark: add spec of copying search results to clipboard - refine cmd subscription to .preview-pane - add cmd subscription to @element --- lib/project-find-view.coffee | 7 ++++--- spec/project-find-view-spec.coffee | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/project-find-view.coffee b/lib/project-find-view.coffee index 9775db8c..0b33bf3e 100644 --- a/lib/project-find-view.coffee +++ b/lib/project-find-view.coffee @@ -132,6 +132,9 @@ class ProjectFindView extends View @subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:use-selection-as-find-pattern': @setSelectionAsFindPattern + @subscriptions.add atom.commands.add '.preview-pane', + 'project-find:copy-search-results': @copySearchResultFromPane + @subscriptions.add atom.commands.add @element, 'find-and-replace:focus-next': => @focusNextElement(1) 'find-and-replace:focus-previous': => @focusNextElement(-1) @@ -143,9 +146,7 @@ class ProjectFindView extends View 'project-find:toggle-case-option': => @toggleCaseOption() 'project-find:toggle-whole-word-option': => @toggleWholeWordOption() 'project-find:replace-all': => @replaceAll() - - @subscriptions.add atom.commands.add 'div.preview-pane', - 'project-find:copy-search-results': @copySearchResultFromPane + 'project-find:copy-search-results': => @copySearchResultFromPane() updateInterfaceForSearching = => @setInfoMessage('Searching...') diff --git a/spec/project-find-view-spec.coffee b/spec/project-find-view-spec.coffee index 73863246..c7ca93a5 100644 --- a/spec/project-find-view-spec.coffee +++ b/spec/project-find-view-spec.coffee @@ -742,6 +742,22 @@ describe 'ProjectFindView', -> expect(resultsPaneView.previewCount.text()).toBe "13 results found in 2 files for items" expect(projectFindView.errorMessages).not.toBeVisible() + it "can copy search results to clipboard", -> + oldClipboardText = atom.clipboard.read() + atom.commands.dispatch(projectFindView[0], 'core:confirm') + + waitsForPromise -> + searchPromise + + runs -> + atom.commands.dispatch(projectFindView[0], 'project-find:copy-search-results') + searchResults = atom.clipboard.read().split('\n') + expect(searchResults[0]).toBe "13 results found in 2 files for items" + expect(searchResults[2]).toBe "sample.coffee (7)" + expect(searchResults[3]).toBe "\t2\tsort: (items) ->" + expect(searchResults[4]).toBe "\t3\treturn items if items.length <= 1" + atom.clipboard.write oldClipboardText + it "only searches paths matching text in the path filter", -> spyOn(atom.workspace, 'scan').andCallFake -> Promise.resolve() projectFindView.pathsEditor.setText('*.js')