Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 8aa9601

Browse files
committed
✅ add spec of copying search results to clipboard
- refine cmd subscription to .preview-pane - add cmd subscription to @element
1 parent d3bddbe commit 8aa9601

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/project-find-view.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class ProjectFindView extends View
132132
@subscriptions.add atom.commands.add 'atom-workspace',
133133
'find-and-replace:use-selection-as-find-pattern': @setSelectionAsFindPattern
134134

135+
@subscriptions.add atom.commands.add '.preview-pane',
136+
'project-find:copy-search-results': @copySearchResultFromPane
137+
135138
@subscriptions.add atom.commands.add @element,
136139
'find-and-replace:focus-next': => @focusNextElement(1)
137140
'find-and-replace:focus-previous': => @focusNextElement(-1)
@@ -143,9 +146,7 @@ class ProjectFindView extends View
143146
'project-find:toggle-case-option': => @toggleCaseOption()
144147
'project-find:toggle-whole-word-option': => @toggleWholeWordOption()
145148
'project-find:replace-all': => @replaceAll()
146-
147-
@subscriptions.add atom.commands.add 'div.preview-pane',
148-
'project-find:copy-search-results': @copySearchResultFromPane
149+
'project-find:copy-search-results': => @copySearchResultFromPane()
149150

150151
updateInterfaceForSearching = =>
151152
@setInfoMessage('Searching...')

spec/project-find-view-spec.coffee

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,22 @@ describe 'ProjectFindView', ->
742742
expect(resultsPaneView.previewCount.text()).toBe "13 results found in 2 files for items"
743743
expect(projectFindView.errorMessages).not.toBeVisible()
744744

745+
it "can copy search results to clipboard", ->
746+
oldClipboardText = atom.clipboard.read()
747+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
748+
749+
waitsForPromise ->
750+
searchPromise
751+
752+
runs ->
753+
atom.commands.dispatch(projectFindView[0], 'project-find:copy-search-results')
754+
searchResults = atom.clipboard.read().split('\n')
755+
expect(searchResults[0]).toBe "13 results found in 2 files for items"
756+
expect(searchResults[2]).toBe "sample.coffee (7)"
757+
expect(searchResults[3]).toBe "\t2\tsort: (items) ->"
758+
expect(searchResults[4]).toBe "\t3\treturn items if items.length <= 1"
759+
atom.clipboard.write oldClipboardText
760+
745761
it "only searches paths matching text in the path filter", ->
746762
spyOn(atom.workspace, 'scan').andCallFake -> Promise.resolve()
747763
projectFindView.pathsEditor.setText('*.js')

0 commit comments

Comments
 (0)