Allow Project Find Results to be copied to clipboard #764

Open
wants to merge 5 commits into
from

Projects

None yet

3 participants

@liuderchi
liuderchi commented Aug 4, 2016 edited

Related issue #416.
copy result of Project-Find to clipboard.

changes:

  1. add Util.copySearchResultFromPane() to copy text of search result pane
  2. add context menu item supporting right-click on project-find result page.
    (of course can use it via command-palette)

demo:
demo

NOTE: hidden entries under collapsed item are not copied to clipboard so that result is consistent with view.

@50Wliu 50Wliu commented on an outdated diff Aug 4, 2016
lib/project-find-view.coffee
@@ -183,6 +186,10 @@ class ProjectFindView extends View
@updateReplaceAllButtonEnablement(@model.getResultsSummary())
@handleEventsForReplace()
+ copySearchResultFromPane: ->
+ atom.clipboard.write(Util.parseSearchResult())
+ atom.notifications.addInfo('Search results are copied to clipboard')
@50Wliu
50Wliu Aug 4, 2016 Member

Search results have been copied to clipboard

@50Wliu 50Wliu commented on an outdated diff Aug 4, 2016
lib/project/util.coffee
@@ -25,3 +26,20 @@ module.exports =
"#{_.pluralize(matchCount, 'result')} found in #{_.pluralize(pathCount, 'file')} for <span class=\"highlight-info\">#{@sanitizePattern(findPattern)}</span>"
else
"No #{if replacedPathCount? then 'more' else ''} results found for '#{@sanitizePattern(findPattern)}'"
+
+ parseSearchResult: () ->
@50Wliu
50Wliu Aug 4, 2016 Member

parseSearchResult: ->

@50Wliu 50Wliu commented on an outdated diff Aug 4, 2016
lib/project/util.coffee
@@ -25,3 +26,20 @@ module.exports =
"#{_.pluralize(matchCount, 'result')} found in #{_.pluralize(pathCount, 'file')} for <span class=\"highlight-info\">#{@sanitizePattern(findPattern)}</span>"
else
"No #{if replacedPathCount? then 'more' else ''} results found for '#{@sanitizePattern(findPattern)}'"
+
+ parseSearchResult: () ->
+ searchResult = []
+ summary = $('span.preview-count', 'div.preview-pane').text()
+ searchResult.push summary, ''
+
+ $('ol.results-view.list-tree>li.path').each () ->
@50Wliu
50Wliu Aug 4, 2016 Member

$('ol.results-view.list-tree>li.path').each ->

@50Wliu 50Wliu commented on an outdated diff Aug 4, 2016
lib/project/util.coffee
@@ -25,3 +26,20 @@ module.exports =
"#{_.pluralize(matchCount, 'result')} found in #{_.pluralize(pathCount, 'file')} for <span class=\"highlight-info\">#{@sanitizePattern(findPattern)}</span>"
else
"No #{if replacedPathCount? then 'more' else ''} results found for '#{@sanitizePattern(findPattern)}'"
+
+ parseSearchResult: () ->
+ searchResult = []
+ summary = $('span.preview-count', 'div.preview-pane').text()
+ searchResult.push summary, ''
+
+ $('ol.results-view.list-tree>li.path').each () ->
+ path = $('span.path-name', @).text()
@50Wliu
50Wliu Aug 4, 2016 Member

Replace @ with this wherever it's not followed by a variable

@50Wliu 50Wliu commented on an outdated diff Aug 4, 2016
lib/project/util.coffee
@@ -25,3 +26,20 @@ module.exports =
"#{_.pluralize(matchCount, 'result')} found in #{_.pluralize(pathCount, 'file')} for <span class=\"highlight-info\">#{@sanitizePattern(findPattern)}</span>"
else
"No #{if replacedPathCount? then 'more' else ''} results found for '#{@sanitizePattern(findPattern)}'"
+
+ parseSearchResult: () ->
+ searchResult = []
+ summary = $('span.preview-count', 'div.preview-pane').text()
+ searchResult.push summary, ''
+
+ $('ol.results-view.list-tree>li.path').each () ->
+ path = $('span.path-name', @).text()
+ matches = $('span.path-match-number', @).text()
+ searchResult.push path + ' ' + matches
+
+ $('li.search-result', @).filter(':visible').each () ->
@50Wliu
50Wliu Aug 4, 2016 Member

Same thing as on line 35.

@50Wliu
Member
50Wliu commented Aug 4, 2016

Very nice! Left you a few comments to resolve the lint errors.

@50Wliu 50Wliu and 1 other commented on an outdated diff Aug 18, 2016
lib/project-find-view.coffee
@@ -146,6 +146,9 @@ class ProjectFindView extends View
'project-find:toggle-whole-word-option': => @toggleWholeWordOption()
'project-find:replace-all': => @replaceAll()
+ @subscriptions.add atom.commands.add 'div.preview-pane',
+ 'project-find:copy-search-result': @copySearchResultFromPane
@50Wliu
50Wliu Aug 18, 2016 Member

-results

@liuderchi
liuderchi Aug 18, 2016

I will update this in menus/find-and-replace.cson also.

@liuderchi

@50Wliu is there anything else I need to change? ๐Ÿ˜ƒ

@50Wliu
Member
50Wliu commented Oct 9, 2016
lib/project/util.coffee
+ preview = $('span.preview', this).text()
+ searchResult.push '\t' + lineNumber + '\t' + preview
+ searchResult.push ''
+ searchResult.join('\n')
@jerone
jerone Nov 22, 2016

Above part could be rewritten with plain DOM API to remove the space-pen dependency with minimal effort. Might help with getting this merged.

@liuderchi
liuderchi Nov 27, 2016 edited

@jerone that's good Idea and I will work on it.

@liuderchi
liuderchi commented Nov 27, 2016 edited

@50Wliu how do think about the format of copied content?

Also I guess spec for this feature is a nice-to-have.

liuderchi added some commits Aug 4, 2016
@liuderchi liuderchi ๐ŸŽจ 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
7b77bb3
@liuderchi liuderchi ๐ŸŽจ fix linter errors, improve notification message 19f6d9f
@liuderchi liuderchi โœ… add spec of copying search results to clipboard
- refine cmd subscription to .preview-pane
- add cmd subscription to @element
a6c9eb9
@liuderchi liuderchi ๐ŸŽจ fix typo 18f53b5
@liuderchi liuderchi ๐ŸŽจ remove space-pen dependency
- output using string interpolation
ce81f75
@liuderchi
liuderchi commented Feb 4, 2017 edited

@50Wliu @jerone this PR now is

  • using DOM API without space-pen dependency
  • having corresponding spec

Anything else I can help?

@50Wliu
Member
50Wliu commented Feb 5, 2017

I don't feel qualified to review this PR, but I'll try to get someone else to take a look at it.

@50Wliu 50Wliu requested a review from maxbrunsfeld Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment