From cc6c64fa5729a07be4567b2ca11bfadec6b02be2 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 15 May 2015 07:27:26 +0100 Subject: Give the vomnibar a (kind of) history. --- background_scripts/completion.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 5755bfaf..2ee4a666 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -226,12 +226,23 @@ class HistoryCompleter @currentSearch = { queryTerms: @queryTerms, onComplete: @onComplete } results = [] HistoryCache.use (history) => + searchUrl = Settings.get "searchUrl" + searchUrlTerminator = new RegExp "[&#/]" results = if queryTerms.length > 0 history.filter (entry) -> RankingUtils.matches(queryTerms, entry.url, entry.title) else [] onComplete results.map (entry) => + # If this history URL starts with the search URL, we reconstruct the original search terms, and insert + # them into the vomnibar when this suggestion is selected. + insertText = + if entry.url.startsWith searchUrl + try + entry.url[searchUrl.length..].split(searchUrlTerminator)[0].split("+").map(decodeURIComponent).join " " + catch + null + new Suggestion queryTerms: queryTerms type: "history" @@ -239,6 +250,7 @@ class HistoryCompleter title: entry.title relevancyFunction: @computeRelevancy relevancyData: entry + insertText: insertText computeRelevancy: (suggestion) -> historyEntry = suggestion.relevancyData -- cgit v1.2.3