mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-09 13:15:37 +03:00
make cmd-shift-f way more awesome
https://img.skitch.com/20111126-b3n8w5kmjnn7bgec1rag8ca2ec.png => https://img.skitch.com/20111126-etrbs62ii92iafcbp3th38wq9k.png
This commit is contained in:
parent
bbc4779f4d
commit
c0cf81f319
@ -1,26 +1,64 @@
|
||||
_ = require 'underscore'
|
||||
$ = require 'jquery'
|
||||
fs = require 'fs'
|
||||
|
||||
ChildProcess = require 'child-process'
|
||||
Browser = require 'browser'
|
||||
Extension = require 'extension'
|
||||
ModalSelector = require 'modal-selector'
|
||||
|
||||
module.exports =
|
||||
class FindInProject extends Extension
|
||||
constructor: ->
|
||||
atom.on 'project:open', @startup
|
||||
class FindInProject extends Browser
|
||||
window.resourceTypes.push this
|
||||
|
||||
startup: (@project) =>
|
||||
running: true
|
||||
|
||||
query: ->
|
||||
return if not @project
|
||||
@findInProject (prompt "Find in project:"), (results) =>
|
||||
@pane = new ModalSelector -> results
|
||||
@pane.show()
|
||||
# Array of { name, url } objects
|
||||
results: []
|
||||
|
||||
# String search term
|
||||
term: ''
|
||||
|
||||
open: (url) ->
|
||||
return if not url
|
||||
|
||||
if match = url.match /^findinproject:\/\/(.+)/
|
||||
@term = match[1]
|
||||
@url = url
|
||||
@title = "Find #{@term}"
|
||||
@findInProject @term, (@results) => @show()
|
||||
true
|
||||
|
||||
findInProject: (term, callback) ->
|
||||
root = @project.url
|
||||
ChildProcess.exec "ack --ignore-dir=Cocoa/build --ignore-dir=vendor #{term} #{@project.url}", (error, stdout, stderr) ->
|
||||
callback _.map (stdout.split "\n"), (line) ->
|
||||
name: line.replace root, ''
|
||||
return callback [] if not url = window.url
|
||||
|
||||
ChildProcess.exec "ack --ignore-dir=Cocoa/build --ignore-dir=vendor #{term} #{url}", (error, stdout, stderr) ->
|
||||
callback _.compact _.map (stdout.split "\n"), (line) ->
|
||||
return if _.isEmpty line.trim()
|
||||
name: line.replace url, ''
|
||||
url: _.first line.split ":"
|
||||
|
||||
add: ->
|
||||
super @innerHTML()
|
||||
|
||||
# gross!
|
||||
iframe = $ $('iframe')[0].contentDocument.body
|
||||
|
||||
iframe.find('#find-in-project-results-view a').click ->
|
||||
window.open this.href.replace 'file://', ''
|
||||
false
|
||||
|
||||
innerHTML: ->
|
||||
html = '''
|
||||
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
|
||||
<style>body { padding:10px; }</style>
|
||||
'''
|
||||
html += '<h1>Results</h1>'
|
||||
html += '<ul id="find-in-project-results-view">'
|
||||
for {name, url} in @results
|
||||
line = _.escape name
|
||||
[file, match...] = line.split ':'
|
||||
match = (match.join ':').replace @term, "<code>#{@term}</code>"
|
||||
html += "<li><a href='#{url}'>#{file}:#{match}</a></li>"
|
||||
html += '</ul>'
|
||||
html
|
@ -1,2 +1,4 @@
|
||||
findinproject:
|
||||
'cmd-shift-f': (findinproject) => findinproject.query()
|
||||
'cmd-shift-f': (findinproject) ->
|
||||
if term = prompt "Find in project:"
|
||||
window.open "findinproject://#{term}"
|
Loading…
Reference in New Issue
Block a user