lib/gitdocs/runner.rb in gitdocs-0.4.10 vs lib/gitdocs/runner.rb in gitdocs-0.4.11
- old
+ new
@@ -11,12 +11,20 @@
@icon = File.expand_path("../../img/icon.png", __FILE__)
end
SearchResult = Struct.new(:file, :context)
def search(term)
+ return [] if term.empty?
+
results = []
if result_test = sh_string("git grep -i #{ShellTools.escape(term)}")
- result_test.scan(/(.*?):([^\n]*)/) { |(file, context)| results << SearchResult.new(file, context) }
+ result_test.scan(/(.*?):([^\n]*)/) do |(file, context)|
+ if result = results.find { |s| s.file == file }
+ result.context += ' ... ' + context
+ else
+ results << SearchResult.new(file, context)
+ end
+ end
end
results
end
def run