aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2012-06-10 00:49:16 -0700
committerPhil Crosby2012-06-10 01:41:45 -0700
commitf761ecf620a103268cb11d49f64768afb4bab08b (patch)
tree2e73d392a3d6a9ee96770a241f9b5154443bc984
parent65c6dd4ccf94660697acfd073ea6e4b714c4eb4f (diff)
downloadvimium-f761ecf620a103268cb11d49f64768afb4bab08b.tar.bz2
Complete tabs in the omnibar.
Right now this is triggered on Shift+T. Firefox also does tab matching in their omnibar. I'm not sure if collapsing the two searches into one UI is a good idea.
-rw-r--r--background_page.html6
-rw-r--r--background_scripts/completion.coffee17
-rw-r--r--tests/completion_test.coffee13
3 files changed, 34 insertions, 2 deletions
diff --git a/background_page.html b/background_page.html
index 8e1d3a6b..ccd06044 100644
--- a/background_page.html
+++ b/background_page.html
@@ -55,14 +55,16 @@
var completionSources = {
bookmarks: new BookmarkCompleter(),
history: new HistoryCompleter(),
- domains: new DomainCompleter()
+ domains: new DomainCompleter(),
+ tabs: new TabCompleter()
};
var completers = {
omni: new MultiCompleter([
completionSources.bookmarks,
completionSources.history,
- completionSources.domains])
+ completionSources.domains]),
+ tabs: new MultiCompleter([completionSources.tabs])
};
chrome.extension.onConnect.addListener(function(port, name) {
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index ce0113f8..4b47f5f2 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -169,6 +169,22 @@ class DomainCompleter
# Suggestions from the Domain completer have the maximum relevancy. They should be shown first in the list.
computeRelevancy: -> 1
+# Searches through all open tabs, matching on title and URL.
+class TabCompleter
+ filter: (queryTerms, onComplete) ->
+ # NOTE(philc): We search all tabs, not just those in the current window. I'm not sure if this is the
+ # correct UX.
+ chrome.tabs.query {}, (tabs) =>
+ results = tabs.filter (tab) -> RankingUtils.matches(queryTerms, tab.url, tab.title)
+ suggestions = results.map (tab) =>
+ suggestion = new Suggestion(queryTerms, "tab", tab.url, tab.title, @computeRelevancy)
+ suggestion.tabId = tab.id
+ suggestion
+ onComplete(suggestions)
+
+ computeRelevancy: (queryTerms, suggestion) ->
+ RankingUtils.wordRelevancy(queryTerms, suggestion.url, suggestion.title)
+
class MultiCompleter
constructor: (@completers) ->
@maxResults = 10 # TODO(philc): Should this be configurable?
@@ -327,5 +343,6 @@ root.BookmarkCompleter = BookmarkCompleter
root.MultiCompleter = MultiCompleter
root.HistoryCompleter = HistoryCompleter
root.DomainCompleter = DomainCompleter
+root.TabCompleter = TabCompleter
root.HistoryCache = HistoryCache
root.RankingUtils = RankingUtils
diff --git a/tests/completion_test.coffee b/tests/completion_test.coffee
index 218225d4..a46dbbf2 100644
--- a/tests/completion_test.coffee
+++ b/tests/completion_test.coffee
@@ -119,6 +119,19 @@ context "domain completer",
should "returns no results when there's more than one query term, because clearly it's not a domain", ->
assert.arrayEqual [], filterCompleter(@completer, ["his", "tory"])
+context "tab completer",
+ setup ->
+ @tabs = [
+ { url: "tab1.com", title: "tab1", id: 1 }
+ { url: "tab2.com", title: "tab2", id: 2 }]
+ chrome.tabs = { query: (args, onComplete) => onComplete(@tabs) }
+ @completer = new TabCompleter()
+
+ should "return matching tabs", ->
+ results = filterCompleter(@completer, ["tab2"])
+ assert.equal "tab2.com", results.map (tab) -> tab.url
+ assert.equal 2, results.map (tab) -> tab.tabId
+
context "suggestions",
should "escape html in page titles", ->
suggestion = new Suggestion(["queryterm"], "tab", "url", "title <span>", returns(1))