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

Commit 1d5b38c

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

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
@@ -134,6 +134,9 @@ class ProjectFindView extends View
134134
@subscriptions.add atom.commands.add 'atom-workspace',
135135
'find-and-replace:use-selection-as-find-pattern': @setSelectionAsFindPattern
136136

137+
@subscriptions.add atom.commands.add '.preview-pane',
138+
'project-find:copy-search-results': @copySearchResultFromPane
139+
137140
@subscriptions.add atom.commands.add @element,
138141
'find-and-replace:focus-next': => @focusNextElement(1)
139142
'find-and-replace:focus-previous': => @focusNextElement(-1)
@@ -145,9 +148,7 @@ class ProjectFindView extends View
145148
'project-find:toggle-case-option': => @toggleCaseOption()
146149
'project-find:toggle-whole-word-option': => @toggleWholeWordOption()
147150
'project-find:replace-all': => @replaceAll()
148-
149-
@subscriptions.add atom.commands.add 'div.preview-pane',
150-
'project-find:copy-search-results': @copySearchResultFromPane
151+
'project-find:copy-search-results': => @copySearchResultFromPane()
151152

152153
updateInterfaceForSearching = =>
153154
@setInfoMessage('Searching...')

spec/project-find-view-spec.coffee

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

707+
it "can copy search results to clipboard", ->
708+
oldClipboardText = atom.clipboard.read()
709+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
710+
711+
waitsForPromise ->
712+
searchPromise
713+
714+
runs ->
715+
atom.commands.dispatch(projectFindView[0], 'project-find:copy-search-results')
716+
searchResults = atom.clipboard.read().split('\n')
717+
expect(searchResults[0]).toBe "13 results found in 2 files for items"
718+
expect(searchResults[2]).toBe "sample.coffee (7)"
719+
expect(searchResults[3]).toBe "\t2\tsort: (items) ->"
720+
expect(searchResults[4]).toBe "\t3\treturn items if items.length <= 1"
721+
atom.clipboard.write oldClipboardText
722+
707723
it "only searches paths matching text in the path filter", ->
708724
spyOn(atom.workspace, 'scan').andCallFake -> Promise.resolve()
709725
projectFindView.pathsEditor.setText('*.js')

0 commit comments

Comments
 (0)