mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Auto-complete matches can be fuzzy-filtered. Typing non-word characters confirms the match automatically.
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.
This commit is contained in:
16
src/stdlib/fuzzy-filter.coffee
Normal file
16
src/stdlib/fuzzy-filter.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
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
|
||||
@@ -16,8 +16,8 @@ $.fn.containsElement = (element) ->
|
||||
(element[0].compareDocumentPosition(this[0]) & 8) == 8
|
||||
|
||||
$.fn.preempt = (eventName, handler) ->
|
||||
@on eventName, (e) ->
|
||||
if handler() == false then e.stopImmediatePropagation()
|
||||
@on eventName, (e, args...) ->
|
||||
if handler(e, args...) == false then e.stopImmediatePropagation()
|
||||
|
||||
eventNameWithoutNamespace = eventName.split('.')[0]
|
||||
handlers = @data('events')[eventNameWithoutNamespace]
|
||||
|
||||
Reference in New Issue
Block a user