From 6f9fd590561b26b01b6e2d3bac8617056af9d9be Mon Sep 17 00:00:00 2001 From: Bernardo B. Marques Date: Fri, 16 Dec 2011 01:21:23 -0200 Subject: refactory of selectTab function --- background_page.html | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/background_page.html b/background_page.html index 77e36bb6..b334f7b1 100644 --- a/background_page.html +++ b/background_page.html @@ -339,15 +339,18 @@ 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; + } selectionChangedHandlers.push(callback); chrome.tabs.update(toSelect.id, { selected: true }); - break; - } - } + }); }); } -- cgit v1.2.3 From ca6f303b3d39f0e7bdeae6d239f124baefc4571b Mon Sep 17 00:00:00 2001 From: Bernardo B. Marques Date: Fri, 16 Dec 2011 01:44:42 -0200 Subject: add support to go to the first or last tab --- background_page.html | 10 +++++++++- commands.js | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/background_page.html b/background_page.html index b334f7b1..5866ee48 100644 --- a/background_page.html +++ b/background_page.html @@ -331,9 +331,11 @@ 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) { @@ -347,6 +349,12 @@ 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 }); diff --git a/commands.js b/commands.js index f36c57b3..d214d2bf 100644 --- a/commands.js +++ b/commands.js @@ -131,6 +131,8 @@ function clearKeyMappingsAndSetDefaults() { "J": "previousTab", "gt": "nextTab", "gT": "previousTab", + "g0": "firstTab", + "g$": "lastTab", "t": "createTab", "x": "removeTab", @@ -195,6 +197,8 @@ var commandDescriptions = { // Manipulating tabs nextTab: ["Go one tab right", { background: true }], previousTab: ["Go one tab left", { background: true }], + firstTab: ["Go to the first tab", { background: true }], + lastTab: ["Go to the last tab", { background: true }], createTab: ["Create new tab", { background: true }], removeTab: ["Close current tab", { background: true }], restoreTab: ["Restore closed tab", { background: true }], @@ -225,7 +229,7 @@ var commandGroups = { historyNavigation: ["goBack", "goForward"], tabManipulation: - ["nextTab", "previousTab", "createTab", "removeTab", "restoreTab"], + ["nextTab", "previousTab", "firstTab", "lastTab", "createTab", "removeTab", "restoreTab"], misc: ["showHelp"] }; -- cgit v1.2.3 From f256c8f7a58eb74aafbed2cb3ec1f7fbb7969a3a Mon Sep 17 00:00:00 2001 From: Bernardo B. Marques Date: Fri, 16 Dec 2011 01:46:01 -0200 Subject: add g$ and g0 docs in README --- README.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.markdown b/README.markdown index 335c3c1f..1a9294f5 100644 --- a/README.markdown +++ b/README.markdown @@ -60,6 +60,8 @@ Manipulating tabs: J, gT go one tab left K, gt go one tab right + g0 go to the first tab + g$ go to the last tab t create tab x close current tab X restore closed tab (i.e. unwind the 'x' command) -- cgit v1.2.3