mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Extract fuzzyFilter function into a file that is shared between file finder and autocompleter. Fix jQuery.fn.preempt to pass its arguments to the event handler.
17 lines
606 B
CoffeeScript
17 lines
606 B
CoffeeScript
stringScore = require 'stringscore'
|
|
|
|
module.exports = (candidates, query, options) ->
|
|
if query
|
|
scoredCandidates = candidates.map (candidate) ->
|
|
string = if options.key? then candidate[options.key] else candidate
|
|
{ candidate, score: stringScore(string, query) }
|
|
|
|
scoredCandidates.sort (a, b) ->
|
|
if a.score > b.score then -1
|
|
else if a.score < b.score then 1
|
|
else 0
|
|
candidates = (scoredCandidate.candidate for scoredCandidate in scoredCandidates when scoredCandidate.score > 0)
|
|
|
|
candidates = candidates[0...options.maxResults] if options.maxResults?
|
|
candidates
|