diff options
| author | Stephen Blott | 2015-05-04 11:55:37 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-05-04 11:55:37 +0100 |
| commit | f9d35083ad511080ee5c01c5c97ef29503f3c0ba (patch) | |
| tree | 76689f25b10f8512f3ac26e3b11057e596ae09c1 | |
| parent | 4e86053f9464c04b9e422625478f8e827f37e533 (diff) | |
| download | vimium-f9d35083ad511080ee5c01c5c97ef29503f3c0ba.tar.bz2 | |
Search completion; simplify/document suggestion options.
| -rw-r--r-- | background_scripts/completion.coffee | 15 | ||||
| -rw-r--r-- | pages/vomnibar.coffee | 4 |
2 files changed, 10 insertions, 9 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index b503a452..f09a079c 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -23,6 +23,11 @@ class Suggestion @title ||= "" # When @autoSelect is truthy, the suggestion is automatically pre-selected in the vomnibar. @autoSelect = false + # If @noHighlightTerms is falsy, then we don't highlight matched terms in the title and URL. + @autoSelect = true + # If @insertText is a string, then the indicated text is inserted into the vomnibar input when the + # suggestion is selected. + @insertText = null computeRelevancy: -> @relevancy = @computeRelevancyFunction(this) @@ -345,7 +350,7 @@ class SearchEngineCompleter if custom query = queryTerms[1..].join " " title = if haveDescription then query else keyword + ": " + query - suggestions.push @mkSuggestion false, queryTerms, type, mkUrl(query), title, @computeRelevancy, 1 + suggestions.push @mkSuggestion null, queryTerms, type, mkUrl(query), title, @computeRelevancy, 1 suggestions[0].autoSelect = true queryTerms = queryTerms[1..] @@ -384,17 +389,13 @@ class SearchEngineCompleter SearchEngines.complete searchUrl, queryTerms, (searchSuggestions = []) => for suggestion in searchSuggestions - suggestions.push @mkSuggestion true, queryTerms, type, mkUrl(suggestion), suggestion, @computeRelevancy, score + insertText = if custom then "#{keyword} #{suggestion}" else suggestion + suggestions.push @mkSuggestion insertText, queryTerms, type, mkUrl(suggestion), suggestion, @computeRelevancy, score score *= 0.9 # Experimental. Force the best match to the top of the list. suggestions[0].extraRelevancyData = 0.9999999 if 0 < suggestions.length - if custom - # For custom search engines, we need to tell the front end to insert the search engine's keyword - # when copying a suggestion into the vomnibar. - suggestion.reinsertPrefix = "#{keyword} " for suggestion in suggestions - # 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 # from other completers. That would potentially be a problem because there is no relationship diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index 3fb63177..8a262e76 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -96,10 +96,10 @@ class VomnibarUI # For suggestions from search-engine completion, we copy the suggested text into the input when selected, # and revert when not. This allows the user to select a suggestion and then continue typing. - if 0 <= @selection and @completions[@selection].insertText + if 0 <= @selection and @completions[@selection].insertText? @previousText ?= @input.value suggestion = @completions[@selection] - @input.value = (suggestion.reinsertPrefix ? "") + suggestion.title + " " + @input.value = @completions[@selection].insertText else if @previousText? @input.value = @previousText @previousText = null |
