From f761ecf620a103268cb11d49f64768afb4bab08b Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sun, 10 Jun 2012 00:49:16 -0700 Subject: 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. --- background_scripts/completion.coffee | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'background_scripts') 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 -- cgit v1.2.3