From 2dfcd17ea485484cedf636a94b9c89c527e2e0b7 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 8 May 2015 09:03:56 +0100 Subject: Search completion; add front end cache. --- background_scripts/completion.coffee | 15 ++++++++++----- background_scripts/completion_engines.coffee | 8 ++++++-- background_scripts/main.coffee | 18 +++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) (limited to 'background_scripts') 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() -- cgit v1.2.3