From b7f94dbcaea5c2bb944dfeaf6f929629834af723 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 18 May 2015 08:10:48 +0100 Subject: Search completion; retain previous (matching) suggestions. This address "UX Issue 2" from #1651. If the user types "w lake vict" and sees a suggestion "lake victoria perch", and continues "w lake vict pe", then we retain the previous suggestion (which still matches) despite the fact that the completion no longer delivers it. This creates a more consistent, Vimium-like vomnibar UX. --- background_scripts/completion.coffee | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 9177298e..8768a39f 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -396,6 +396,7 @@ class TabCompleter class SearchEngineCompleter @debug: false searchEngines: null + previousSuggestions: null cancel: -> CompletionSearch.cancel() @@ -415,6 +416,7 @@ class SearchEngineCompleter engine: engines[keyword] refresh: (port) -> + @previousSuggestions = {} # Parse the search-engine configuration. @searchEngines = new AsyncDataFetcher (callback) -> engines = {} @@ -478,6 +480,12 @@ class SearchEngineCompleter # And the URL suffix (which must contain the query part) matches the current query. RankingUtils.matches queryTerms, suggestion.url[engine.searchUrlPrefix.length..]) + previousSuggestions = + for url, suggestion of @previousSuggestions + continue unless RankingUtils.matches queryTerms, suggestion.title + suggestion.relevancy = null + suggestion + primarySuggestion = new Suggestion queryTerms: queryTerms type: description @@ -491,7 +499,8 @@ class SearchEngineCompleter mkSuggestion = do => count = 0 (suggestion) => - new Suggestion + url = Utils.createSearchUrl suggestion, searchUrl + @previousSuggestions[url] = new Suggestion queryTerms: queryTerms type: description url: Utils.createSearchUrl suggestion, searchUrl @@ -508,7 +517,7 @@ class SearchEngineCompleter cachedSuggestions = if haveCompletionEngine then CompletionSearch.complete searchUrl, queryTerms else null - suggestions = [] + suggestions = previousSuggestions suggestions.push primarySuggestion if custom suggestions.push cachedSuggestions.map(mkSuggestion)... if custom and cachedSuggestions? -- cgit v1.2.3 From 4ec5e46ece2cd12d5ebb8db6a8ebcb8690687a1f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 18 May 2015 08:23:16 +0100 Subject: Search completion; retain previous suggestions (comments and tweaks). --- background_scripts/completion.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 8768a39f..e6e8deaf 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -480,9 +480,14 @@ class SearchEngineCompleter # And the URL suffix (which must contain the query part) matches the current query. RankingUtils.matches queryTerms, suggestion.url[engine.searchUrlPrefix.length..]) + # If a previous suggestion still matches the query, then we keep it (even if the completion engine may not + # return it for the current query). This allows the user to pick suggestions by typing fragments of their + # text, without regard to whether the completion engine can complete the actual text of the query. previousSuggestions = for url, suggestion of @previousSuggestions continue unless RankingUtils.matches queryTerms, suggestion.title + # Reset the previous relevancy and HTML, they may not be correct wrt. the current query. + extend suggestion, relevancy: null, html: null suggestion.relevancy = null suggestion -- cgit v1.2.3 From a1e26d83b7f34ad230a51cdb4cb17224522a39dd Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 18 May 2015 08:45:21 +0100 Subject: Search completion; retain previous suggestions (tweak highlighting). --- background_scripts/completion.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index e6e8deaf..39ec66c5 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -52,7 +52,7 @@ class Suggestion
""" @@ -114,6 +114,9 @@ class Suggestion string.substring(end) string + highlightUrlTerms: (string) -> + if @highlightTermsExcludeUrl then string else @highlightQueryTerms string + # Merges the given list of ranges such that any overlapping regions are combined. E.g. # mergeRanges([0, 4], [3, 6]) => [0, 6]. A range is [startIndex, endIndex]. mergeRanges: (ranges) -> @@ -486,8 +489,8 @@ class SearchEngineCompleter previousSuggestions = for url, suggestion of @previousSuggestions continue unless RankingUtils.matches queryTerms, suggestion.title - # Reset the previous relevancy and HTML, they may not be correct wrt. the current query. - extend suggestion, relevancy: null, html: null + # Reset various fields, they may not be correct wrt. the current query. + extend suggestion, relevancy: null, html: null, highlightTerms: true, queryTerms: queryTerms suggestion.relevancy = null suggestion @@ -512,6 +515,7 @@ class SearchEngineCompleter title: suggestion insertText: suggestion highlightTerms: false + highlightTermsExcludeUrl: true isCustomSearch: custom # The first (top) suggestion gets a score of 1. This puts it two