diff options
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/completion.coffee | 25 | ||||
| -rw-r--r-- | background_scripts/completion_engines.coffee | 7 |
2 files changed, 15 insertions, 17 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 18bfafd1..746e662d 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -197,7 +197,7 @@ class HistoryCompleter history.filter (entry) -> RankingUtils.matches(queryTerms, entry.url, entry.title) else [] - suggestions = results.map (entry) => + onComplete results.map (entry) => new Suggestion queryTerms: queryTerms type: "history" @@ -205,7 +205,6 @@ class HistoryCompleter title: entry.title relevancyFunction: @computeRelevancy relevancyData: entry - onComplete suggestions computeRelevancy: (suggestion) -> historyEntry = suggestion.relevancyData @@ -232,16 +231,15 @@ class DomainCompleter performSearch: (queryTerms, onComplete) -> query = queryTerms[0] - domainCandidates = (domain for domain of @domains when domain.indexOf(query) >= 0) - domains = @sortDomainsByRelevancy(queryTerms, domainCandidates) - return onComplete([]) if domains.length == 0 - topDomain = domains[0][0] - suggestion = new Suggestion - queryTerms: queryTerms - type: "domain" - url: topDomain - relevancy: 1 - onComplete [ suggestion ] + domains = (domain for domain of @domains when 0 <= domain.indexOf query) + domains = @sortDomainsByRelevancy queryTerms, domains + onComplete [ + new Suggestion + queryTerms: queryTerms + type: "domain" + url: domains[0]?[0] ? "" # This is the URL or an empty string, but not null. + relevancy: 1 + ].filter (s) -> 0 < s.url.length # Returns a list of domains of the form: [ [domain, relevancy], ... ] sortDomainsByRelevancy: (queryTerms, domainCandidates) -> @@ -656,8 +654,7 @@ HistoryCache = @callbacks = null use: (callback) -> - return @fetchHistory(callback) unless @history? - callback(@history) + if @history? then callback @history else @fetchHistory callback fetchHistory: (callback) -> return @callbacks.push(callback) if @callbacks diff --git a/background_scripts/completion_engines.coffee b/background_scripts/completion_engines.coffee index 8a880930..3e762e32 100644 --- a/background_scripts/completion_engines.coffee +++ b/background_scripts/completion_engines.coffee @@ -136,7 +136,6 @@ CompletionEngines = xhr.onreadystatechange = -> if xhr.readyState == 4 - console.log xhr.getAllResponseHeaders() callback(if xhr.status == 200 then xhr else null) # Look up the completion engine for this searchUrl. Because of DummyCompletionEngine, above, we know there @@ -214,6 +213,7 @@ CompletionEngines = if handler != @mostRecentHandler # Bail if another completion has begun, or the user is typing. console.log "bail", completionCacheKey if @debug return callback [] + @mostRecentHandler = null # Don't allow duplicate identical active requests. This can happen, for example, when the user enters or # removes a space, or when they enter a character and immediately delete it. @inTransit ?= {} @@ -228,8 +228,9 @@ CompletionEngines = callback suggestions for callback in queue cancel: -> - console.log "cancel (user is typing)" if @debug and @mostRecentHandler? - @mostRecentHandler = null + if @mostRecentHandler? + @mostRecentHandler = null + console.log "cancel (user is typing)" if @debug root = exports ? window root.CompletionEngines = CompletionEngines |
