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

Commit

Permalink
✅ add spec of copying search results to clipboard
Browse files Browse the repository at this point in the history
- refine cmd subscription to .preview-pane
- add cmd subscription to @element
  • Loading branch information
liuderchi committed Nov 28, 2016
1 parent 9cd6ca7 commit 1d5b38c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/project-find-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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)
Expand All @@ -145,9 +148,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...')
Expand Down
16 changes: 16 additions & 0 deletions spec/project-find-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,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')
Expand Down

0 comments on commit 1d5b38c

Please sign in to comment.