aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-05-07 09:25:15 +0100
committerStephen Blott2015-05-07 09:25:15 +0100
commit430bdc8bdf7c109a3007104fc06abeeed1891529 (patch)
tree8a7d83fe05c735cb5829e0da26adf40e0703ed79 /background_scripts
parentc7fb211f0d1a6504bd0cbb94395f9437f858f2c0 (diff)
downloadvimium-430bdc8bdf7c109a3007104fc06abeeed1891529.tar.bz2
Search completion; tweak domain completer.
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee25
-rw-r--r--background_scripts/completion_engines.coffee7
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