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

Commit ed31dd0

Browse files
committed
🎨 copy search result of project-find to clipboard
- add copySearchResultFromPane() to copy text of search result pane - add context menu item for right-click on result page
1 parent 98ccade commit ed31dd0

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

lib/project-find-view.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class ProjectFindView extends View
146146
'project-find:toggle-whole-word-option': => @toggleWholeWordOption()
147147
'project-find:replace-all': => @replaceAll()
148148

149+
@subscriptions.add atom.commands.add 'div.preview-pane',
150+
'project-find:copy-search-result': @copySearchResultFromPane
151+
149152
updateInterfaceForSearching = =>
150153
@setInfoMessage('Searching...')
151154

@@ -183,6 +186,10 @@ class ProjectFindView extends View
183186
@updateReplaceAllButtonEnablement(@model.getResultsSummary())
184187
@handleEventsForReplace()
185188

189+
copySearchResultFromPane: ->
190+
atom.clipboard.write(Util.parseSearchResult())
191+
atom.notifications.addInfo('Search results are copied to clipboard')
192+
186193
handleEventsForReplace: ->
187194
@replaceEditor.getModel().getBuffer().onDidChange => @model.clearReplacementState()
188195
@replaceEditor.getModel().onDidStopChanging => @model.getFindOptions().set(replacePattern: @replaceEditor.getText())

lib/project/util.coffee

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_ = require 'underscore-plus'
2+
{$} = require 'atom-space-pen-views'
23

34
module.exports =
45
escapeHtml: (str) ->
@@ -25,3 +26,20 @@ module.exports =
2526
"#{_.pluralize(matchCount, 'result')} found in #{_.pluralize(pathCount, 'file')} for <span class=\"highlight-info\">#{@sanitizePattern(findPattern)}</span>"
2627
else
2728
"No #{if replacedPathCount? then 'more' else ''} results found for '#{@sanitizePattern(findPattern)}'"
29+
30+
parseSearchResult: () ->
31+
searchResult = []
32+
summary = $('span.preview-count', 'div.preview-pane').text()
33+
searchResult.push summary, ''
34+
35+
$('ol.results-view.list-tree>li.path').each () ->
36+
path = $('span.path-name', @).text()
37+
matches = $('span.path-match-number', @).text()
38+
searchResult.push path + ' ' + matches
39+
40+
$('li.search-result', @).filter(':visible').each () ->
41+
lineNumber = $('span.line-number', @).text()
42+
preview = $('span.preview', @).text()
43+
searchResult.push '\t' + lineNumber + '\t' + preview
44+
searchResult.push ''
45+
searchResult.join('\n')

menus/find-and-replace.cson

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
'.tree-view > li.directory': [
2525
{ 'label': 'Search in Directory', 'command': 'project-find:show-in-current-directory' }
2626
]
27+
28+
'div.preview-pane': [
29+
{ 'label': 'Copy to Clipboard', 'command': 'project-find:copy-search-result' }
30+
]

0 commit comments

Comments
 (0)