diff options
Diffstat (limited to 'lib/completion.js')
| -rw-r--r-- | lib/completion.js | 45 | 
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/completion.js b/lib/completion.js index afdb7f55..f78a9e39 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -213,6 +213,10 @@ var completion = (function() {          (fuzzyMatcher.calculateRelevancy(query, this.extractStringFromMatch(match)) + 1);      }, +    createAction: function(match) { +      return createActionOpenUrl(match.url); +    }, +      filter: function(query, callback) {        var self = this; @@ -224,7 +228,7 @@ var completion = (function() {                              function(match) {            filtered.push(createHighlightingCompletion(                  query, match.str, -                createActionOpenUrl(match.url), +                self.createAction(match),                  self.calculateRelevancy(query, match)));          });          callback(filtered); @@ -377,6 +381,44 @@ var completion = (function() {      port.postMessage();    } +  /** A fuzzy tab completer */ +  var FuzzyTabCompleter = function() { +    AsyncFuzzyUrlCompleter.call(this); +  } +  FuzzyTabCompleter.prototype = new AsyncFuzzyUrlCompleter; +  FuzzyTabCompleter.prototype.createAction = function(match) { +    var open = function() { +      chrome.extension.sendRequest({ handler: 'selectSpecificTab', id: match.tab.id }); +    } +    return [ open, open ]; +  } +  FuzzyTabCompleter.prototype.refresh = function() { +    this.completions = null; // reset completions + +    var port = chrome.extension.connect({ name: 'getTabsInCurrentWindow' }) ; +    var self = this; +    port.onMessage.addListener(function(msg) { +      var results = []; + +      for (var i = 0; i < msg.tabs.length; ++i) { +        var tab = msg.tabs[i]; + +        var title = ''; +        if (tab.title.length > 0) +          title = ' <span class="title">' + tab.title + '</span>'; + +        results.push({ +          str: '<em>tab</em> ' + tab.url + title, +          url: tab.url, +          tab: tab, +        }); +      } +      port = null; +      self.readyCallback(results); +    }); +    port.postMessage(); +  } +    /** A meta-completer that delegates queries and merges and sorts the results of a collection of other     * completer instances. */    var MergingCompleter = function(sources) { @@ -412,6 +454,7 @@ var completion = (function() {    return {      FuzzyHistoryCompleter: FuzzyHistoryCompleter,      FuzzyBookmarkCompleter: FuzzyBookmarkCompleter, +    FuzzyTabCompleter: FuzzyTabCompleter,      SmartCompleter: SmartCompleter,      MergingCompleter: MergingCompleter,    };  | 
