aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2014-12-30 16:14:23 +0000
committerStephen Blott2014-12-30 16:14:23 +0000
commit214ecb92caa8fc5a71dd3cac70a7280e1de08ccd (patch)
treebd8312058bd452828dd405d481caae7f8a7f00c3 /background_scripts
parent8f998f5b4cd1d8600b62ae7faac8afb91c4d2dab (diff)
parent74b5c1a9bb54bbc2a2c9d30925d514e02a5515f7 (diff)
downloadvimium-214ecb92caa8fc5a71dd3cac70a7280e1de08ccd.tar.bz2
Merge branch 'search-engine-descriptions' of https://github.com/smblott-github/vimium into smblott-github-search-engine-descriptions
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee16
-rw-r--r--background_scripts/settings.coffee18
2 files changed, 23 insertions, 11 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index d62f82fe..4e570313 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -324,11 +324,17 @@ class SearchEngineCompleter
searchEngines: {}
filter: (queryTerms, onComplete) ->
- searchEngineMatch = this.getSearchEngineMatches(queryTerms[0])
+ {url: url, description: description} = this.getSearchEngineMatches(queryTerms[0])
suggestions = []
- if searchEngineMatch
- searchEngineMatch = searchEngineMatch.replace(/%s/g, Utils.createSearchQuery queryTerms[1..])
- suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy)
+ if url
+ url = url.replace(/%s/g, Utils.createSearchQuery queryTerms[1..])
+ if description
+ type = description
+ query = queryTerms[1..].join " "
+ else
+ type = "search"
+ query = queryTerms[0] + ": " + queryTerms[1..].join(" ")
+ suggestion = new Suggestion(queryTerms, type, url, query, @computeRelevancy)
suggestions.push(suggestion)
onComplete(suggestions)
@@ -338,7 +344,7 @@ class SearchEngineCompleter
this.searchEngines = root.Settings.getSearchEngines()
getSearchEngineMatches: (queryTerm) ->
- this.searchEngines[queryTerm]
+ this.searchEngines[queryTerm] || {}
# A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the top
# 10. Queries from the vomnibar frontend script come through a multi completer.
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index e90bc1f8..2fc3b43d 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -46,13 +46,19 @@ root.Settings = Settings =
# this is a map that we use to store our search engines for use.
searchEnginesMap: {}
- # this parses the search engines settings and clears the old searchEngines and sets the new one
+ # Parse the custom search engines setting and cache it.
parseSearchEngines: (searchEnginesText) ->
@searchEnginesMap = {}
- # find the split pairs by first splitting by line then splitting on the first `: `
- split_pairs = ( pair.split( /: (.+)/, 2) for pair in searchEnginesText.split( /\n/ ) when pair[0] != "#" )
- @searchEnginesMap[a[0]] = a[1] for a in split_pairs
- @searchEnginesMap
+ for line in searchEnginesText.split /\n/
+ tokens = line.trim().split /\s+/
+ continue if tokens.length < 2 or tokens[0].startsWith('"') or tokens[0].startsWith("#")
+ keywords = tokens[0].split ":"
+ continue unless keywords.length == 2 and not keywords[1] # So, like: [ "w", "" ].
+ @searchEnginesMap[keywords[0]] =
+ url: tokens[1]
+ description: tokens[2..].join(" ")
+
+ # Fetch the search-engine map, building it if necessary.
getSearchEngines: ->
this.parseSearchEngines(@get("searchEngines") || "") if Object.keys(@searchEnginesMap).length == 0
@searchEnginesMap
@@ -105,7 +111,7 @@ root.Settings = Settings =
# default/fall back search engine
searchUrl: "http://www.google.com/search?q="
# put in an example search engine
- searchEngines: "w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s"
+ searchEngines: "w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s wikipedia"
newTabUrl: "chrome://newtab"
settingsVersion: Utils.getCurrentVersion()