From e27da85676a9d62145ed7ef56e125de2e133ae10 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 27 May 2015 08:34:15 +0100 Subject: Custom-only: single-line completions for custom search engines. --- background_scripts/completion.coffee | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 7a5f37bf..3238f744 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -41,23 +41,32 @@ class Suggestion # or @relevancyFunction. @relevancy ?= @relevancyFunction this - generateHtml: -> + generateHtml: (request) -> return @html if @html relevancyHtml = if @showRelevancy then "#{@computeRelevancy()}" else "" insertTextClass = if @insertText then "vomnibarInsertText" else "vomnibarNoInsertText" insertTextIndicator = "↪" # A right hooked arrow. + @title = @insertText if @insertText and request.isCustomSearch # NOTE(philc): We're using these vimium-specific class names so we don't collide with the page's CSS. @html = - """ -
- #{insertTextIndicator}#{@type} - #{@highlightQueryTerms Utils.escapeHtml @title} -
-
- #{insertTextIndicator}#{@highlightUrlTerms Utils.escapeHtml @shortenUrl()} - #{relevancyHtml} -
- """ + if request.isCustomSearch + """ +
+ #{insertTextIndicator}#{@type} + #{@highlightQueryTerms Utils.escapeHtml @title} +
+ """ + else + """ +
+ #{insertTextIndicator}#{@type} + #{@highlightQueryTerms Utils.escapeHtml @title} +
+
+ #{insertTextIndicator}#{@highlightUrlTerms Utils.escapeHtml @shortenUrl()} + #{relevancyHtml} +
+ """ # Use neat trick to snatch a domain (http://stackoverflow.com/a/8498668). getUrlRoot: (url) -> @@ -419,6 +428,7 @@ class SearchEngineCompleter queryTerms: queryTerms[1..] keyword: keyword engine: engines[keyword] + isCustomSearch: true refresh: (port) -> @previousSuggestions = {} @@ -662,7 +672,7 @@ class MultiCompleter completer.postProcessSuggestions? request, suggestions for completer in @completers # Generate HTML for the remaining suggestions and return them. - suggestion.generateHtml() for suggestion in suggestions + suggestion.generateHtml request for suggestion in suggestions suggestions # Utilities which help us compute a relevancy score for a given item. -- cgit v1.2.3