diff options
| author | Stephen Blott | 2015-05-08 09:03:56 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-05-08 09:03:56 +0100 |
| commit | 2dfcd17ea485484cedf636a94b9c89c527e2e0b7 (patch) | |
| tree | 9e768056ffa70a79ca8ff9c2d1d5177755ed0652 /background_scripts | |
| parent | 898c21808c709a1a551fa15bb82f6a3bb4810aae (diff) | |
| download | vimium-2dfcd17ea485484cedf636a94b9c89c527e2e0b7.tar.bz2 | |
Search completion; add front end cache.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/completion.coffee | 15 | ||||
| -rw-r--r-- | background_scripts/completion_engines.coffee | 8 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 18 |
3 files changed, 25 insertions, 16 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 746e662d..f17ca28c 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -491,22 +491,27 @@ class MultiCompleter # (ie. a SearchEngineCompleter). This prevents hiding the vomnibar briefly before showing it # again, which looks ugly. unless shouldRunContinuation and suggestions.length == 0 - onComplete @prepareSuggestions queryTerms, suggestions + onComplete + results: @prepareSuggestions queryTerms, suggestions + callerMayCacheResults: not shouldRunContinuation # Allow subsequent queries to begin. @filterInProgress = false if shouldRunContinuation continuation suggestions, (newSuggestions) => if 0 < newSuggestions.length - onComplete @prepareSuggestions queryTerms, suggestions.concat newSuggestions + suggestions.push newSuggestions... + onComplete + results: @prepareSuggestions queryTerms, suggestions + callerMayCacheResults: true else @filter @mostRecentQuery.queryTerms, @mostRecentQuery.onComplete if @mostRecentQuery prepareSuggestions: (queryTerms, suggestions) -> suggestion.computeRelevancy queryTerms for suggestion in suggestions suggestions.sort (a, b) -> b.relevancy - a.relevancy - suggestions = suggestions[0...@maxResults] - suggestion.generateHtml() for suggestion in suggestions - suggestions + for suggestion in suggestions[0...@maxResults] + suggestion.generateHtml() + suggestion # Utilities which help us compute a relevancy score for a given item. RankingUtils = diff --git a/background_scripts/completion_engines.coffee b/background_scripts/completion_engines.coffee index 19a18ecd..52db90d0 100644 --- a/background_scripts/completion_engines.coffee +++ b/background_scripts/completion_engines.coffee @@ -209,9 +209,13 @@ CompletionEngines = # We pause in case the user is still typing. Utils.setTimeout @delay, handler = @mostRecentHandler = => - if handler != @mostRecentHandler # Bail if another completion has begun, or the user is typing. + if handler != @mostRecentHandler + # Bail! Another completion has begun, or the user is typing. + # NOTE: We do *not* call the callback (because we are not providing results, and we don't want allow + # any higher-level component to cache the results -- specifically, the vomnibar itself, via + # callerMayCacheResults). console.log "bail", completionCacheKey if @debug - return callback [] + return @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. diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index a3ddb48c..1a3281bf 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -43,26 +43,26 @@ chrome.storage.local.set vimiumSecret: Math.floor Math.random() * 2000000000 completionSources = - bookmarks: new BookmarkCompleter() - history: new HistoryCompleter() - domains: new DomainCompleter() - tabs: new TabCompleter() - searchEngines: new SearchEngineCompleter() + bookmarks: new BookmarkCompleter + history: new HistoryCompleter + domains: new DomainCompleter + tabs: new TabCompleter + searchEngines: new SearchEngineCompleter completers = omni: new MultiCompleter [ completionSources.bookmarks completionSources.history completionSources.domains - # This comes last, because it delivers additional, asynchronous results. completionSources.searchEngines ] - bookmarks: new MultiCompleter([completionSources.bookmarks]) - tabs: new MultiCompleter([completionSources.tabs]) + bookmarks: new MultiCompleter [completionSources.bookmarks] + tabs: new MultiCompleter [completionSources.tabs] completionHandlers = filter: (completer, args, port) -> - completer.filter args.queryTerms, (results) -> port.postMessage id: args.id, results: results + completer.filter args.queryTerms, (response) -> + port.postMessage extend args, response refresh: (completer) -> completer.refresh() cancel: (completer) -> completer.cancel() |
