diff options
| -rw-r--r-- | background_page.html | 18 | ||||
| -rw-r--r-- | fuzzyMode.js | 1 | ||||
| -rw-r--r-- | lib/completion.js | 45 |
3 files changed, 62 insertions, 2 deletions
diff --git a/background_page.html b/background_page.html index 97017fad..0f86e3ce 100644 --- a/background_page.html +++ b/background_page.html @@ -29,6 +29,7 @@ getBookmarks: getBookmarks, getAllBookmarks: getAllBookmarks, getHistory: getHistory, + getTabsInCurrentWindow: getTabsInCurrentWindow, }; var sendRequestHandlers = { @@ -43,7 +44,8 @@ updateScrollPosition: handleUpdateScrollPosition, copyToClipboard: copyToClipboard, isEnabledForUrl: isEnabledForUrl, - saveHelpDialogSettings: saveHelpDialogSettings + saveHelpDialogSettings: saveHelpDialogSettings, + selectSpecificTab: selectSpecificTab, }; // Event handlers @@ -259,6 +261,14 @@ Clipboard.copy(request.data); } + /** + * Selects the tab with the ID specified in request.id + */ + function selectSpecificTab(request) { + console.log("selectSpecificTab"); + chrome.tabs.update(request.id, { selected: true }); + } + /* * Used by the content scripts to get settings from the local storage. */ @@ -305,6 +315,12 @@ }); }; + function getTabsInCurrentWindow(args, port) { + chrome.tabs.getAllInWindow(null, function(tabs) { + port.postMessage({tabs:tabs}); + }); + }; + /* * Used by everyone to get settings from local storage. */ diff --git a/fuzzyMode.js b/fuzzyMode.js index 41fc061b..32f54eb9 100644 --- a/fuzzyMode.js +++ b/fuzzyMode.js @@ -13,6 +13,7 @@ var fuzzyMode = (function() { }), new completion.FuzzyHistoryCompleter(500), new completion.FuzzyBookmarkCompleter(), + new completion.FuzzyTabCompleter(), ]); completer.refresh(); fuzzyBox = new FuzzyBox(completer, 10); 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, }; |
