aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya2011-12-18 12:19:14 -0800
committerIlya2011-12-18 12:19:14 -0800
commit11db66b52ec0435352801d276dc3fd97583a56e1 (patch)
treeb237ff68a1e7c2dd82088ffb8f8f85a518e2bda9
parent28c763c9ac375cd6997ff8a293af5c09906b8c95 (diff)
parentf256c8f7a58eb74aafbed2cb3ec1f7fbb7969a3a (diff)
downloadvimium-11db66b52ec0435352801d276dc3fd97583a56e1.tar.bz2
Merge pull request #421 from bernardofire/tabs
solve issue #405
-rw-r--r--README.markdown2
-rw-r--r--background_page.html27
-rw-r--r--commands.js6
3 files changed, 26 insertions, 9 deletions
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)
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;
- }
- }
+ });
});
}
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"]
};