aboutsummaryrefslogtreecommitdiffstats
path: root/background_page.html
diff options
context:
space:
mode:
authorIlya2011-12-18 12:19:14 -0800
committerIlya2011-12-18 12:19:14 -0800
commit11db66b52ec0435352801d276dc3fd97583a56e1 (patch)
treeb237ff68a1e7c2dd82088ffb8f8f85a518e2bda9 /background_page.html
parent28c763c9ac375cd6997ff8a293af5c09906b8c95 (diff)
parentf256c8f7a58eb74aafbed2cb3ec1f7fbb7969a3a (diff)
downloadvimium-11db66b52ec0435352801d276dc3fd97583a56e1.tar.bz2
Merge pull request #421 from bernardofire/tabs
solve issue #405
Diffstat (limited to 'background_page.html')
-rw-r--r--background_page.html27
1 files changed, 19 insertions, 8 deletions
diff --git a/background_page.html b/background_page.html
index 77e36bb6..5866ee48 100644
--- a/background_page.html
+++ b/background_page.html
@@ -331,23 +331,34 @@
function nextTab(callback) { selectTab(callback, "next"); }
function previousTab(callback) { selectTab(callback, "previous"); }
+ function firstTab(callback) { selectTab(callback, "first"); }
+ function lastTab(callback) { selectTab(callback, "last"); }
/*
- * Selects a tab before or after the currently selected tab. Direction is either "next" or "previous".
+ * Selects a tab before or after the currently selected tab. Direction is either "next", "previous", "first" or "last".
*/
function selectTab(callback, direction) {
chrome.tabs.getAllInWindow(null, function(tabs) {
if (tabs.length <= 1)
return;
- for (var i = 0; i < tabs.length; i++) {
- if (tabs[i].selected) {
- var delta = (direction == "next") ? 1 : -1;
- var toSelect = tabs[(i + delta + tabs.length) % tabs.length];
+ chrome.tabs.getSelected(null, function(currentTab) {
+ switch (direction) {
+ case "next":
+ toSelect = tabs[(currentTab.index + 1 + tabs.length) % tabs.length];
+ break;
+ case "previous":
+ toSelect = tabs[(currentTab.index - 1 + tabs.length) % tabs.length];
+ break;
+ case "first":
+ toSelect = tabs[0];
+ break;
+ case "last":
+ toSelect = tabs[tabs.length - 1];
+ break;
+ }
selectionChangedHandlers.push(callback);
chrome.tabs.update(toSelect.id, { selected: true });
- break;
- }
- }
+ });
});
}