diff options
| author | Stephen Blott | 2015-05-06 07:40:46 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-05-06 09:29:15 +0100 |
| commit | 5752c0ead0a65fc2329515509f66e00bd6ee2f60 (patch) | |
| tree | 0cc13d0e924c0daf69312036f2dc1fe28aa84494 /background_scripts/completion.coffee | |
| parent | 372e65d7b44c3f0ad3f522bd6b8c9cfacd693186 (diff) | |
| download | vimium-5752c0ead0a65fc2329515509f66e00bd6ee2f60.tar.bz2 | |
Search completion; more tweaks.
Diffstat (limited to 'background_scripts/completion.coffee')
| -rw-r--r-- | background_scripts/completion.coffee | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 4ae0c44b..bffb9700 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -363,23 +363,22 @@ class SearchEngineCompleter haveDescription = description? and 0 < description.length description ||= "#{if custom then "custom " else ""}search" + queryTerms = queryTerms[1..] if custom + query = queryTerms.join " " + + if queryTerms.length == 0 + return onComplete suggestions + # For custom search engines, we add an auto-selected suggestion. if custom - queryTerms = queryTerms[1..] - query = queryTerms.join " " suggestions.push new Suggestion queryTerms: queryTerms type: description - url: searchUrl.replace /%s/g, Utils.createSearchQuery query.split /\s+/ - title: if haveDescription then query else "#{keyword}: #{query}" + url: Utils.createSearchUrl queryTerms, searchUrl + title: if haveDescription then query else "#{keyword}: #{query}" relevancy: 1 - autoSelect: true highlightTerms: false - else - query = queryTerms.join " " - - if queryTerms.length == 0 - return onComplete suggestions + autoSelect: true onComplete suggestions, (existingSuggestions, onComplete) => suggestions = [] @@ -399,23 +398,22 @@ class SearchEngineCompleter relavancy = 0.6 * (Math.min(characterCount, 10.0)/10.0) if 0 < existingSuggestions.length - existingSuggestionMinScore = existingSuggestions[existingSuggestions.length-1].relevancy - if relavancy < existingSuggestionMinScore and MultiCompleter.maxResults <= existingSuggestions.length + existingSuggestionsMinScore = existingSuggestions[existingSuggestions.length-1].relevancy + if relavancy < existingSuggestionsMinScore and MultiCompleter.maxResults <= existingSuggestions.length # No suggestion we propose will have a high enough relavancy to beat the existing suggestions, so bail # immediately. return onComplete [] - CompletionEngines.complete searchUrl, queryTerms, (searchSuggestions = []) => - for suggestion in searchSuggestions + CompletionEngines.complete searchUrl, queryTerms, (completionSuggestions = []) => + for suggestion in completionSuggestions suggestions.push new Suggestion queryTerms: queryTerms type: description - url: searchUrl.replace /%s/g, Utils.createSearchQuery suggestion.split /\s+/ + url: Utils.createSearchUrl suggestion, searchUrl title: suggestion - relevancy: relavancy - insertText: if custom then "#{keyword} #{suggestion}" else suggestion + relevancy: relavancy *= 0.9 highlightTerms: false - relavancy *= 0.9 + insertText: if custom then "#{keyword} #{suggestion}" else suggestion # We keep at least three suggestions (if possible) and at most six. We keep more than three only if # there are enough slots. The idea is that these suggestions shouldn't wholly displace suggestions @@ -501,7 +499,8 @@ class MultiCompleter @filterInProgress = false if shouldRunContinuation continuation suggestions, (newSuggestions) => - onComplete @prepareSuggestions queryTerms, suggestions.concat newSuggestions + if 0 < newSuggestions.length + onComplete @prepareSuggestions queryTerms, suggestions.concat newSuggestions else @filter @mostRecentQuery.queryTerms, @mostRecentQuery.onComplete if @mostRecentQuery |
