aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2009-11-08 00:45:33 -0800
committerPhil Crosby2009-11-08 00:46:34 -0800
commit10c0d5bbaa00afcafbdc7df2b456e72203fcb36d (patch)
tree0730ef022993db0e548edd54dfe762f0a0cd5e0b
parent4828c9b56585bbf0e090934187cc5397df4536cd (diff)
downloadvimium-10c0d5bbaa00afcafbdc7df2b456e72203fcb36d.tar.bz2
Add commands for selecting the next tab and previous tab.
-rw-r--r--background_page.html24
1 files changed, 24 insertions, 0 deletions
diff --git a/background_page.html b/background_page.html
index fc19fa4a..7ba89c41 100644
--- a/background_page.html
+++ b/background_page.html
@@ -62,6 +62,27 @@
chrome.tabs.create({}, function(tab) { callback(); });
}
+ function nextTab() { selectTab("next"); }
+ function previousTab() { selectTab("previous"); }
+
+ /*
+ * Selects a tab before or after the currently selected tab. Direction is either "next" or "previous".
+ */
+ function selectTab(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.update(toSelect.id, { selected: true });
+ break;
+ }
+ }
+ });
+ }
+
function removeTab(callback) {
getCurrentTabWithScrollPosition(function(tab, scrollX, scrollY) {
tabQueue.push({ tabUrl: tab.url, scrollX: scrollX, scrollY: scrollY });
@@ -108,6 +129,9 @@
keyToCommandRegistry['fo'] = 'goForward';
keyToCommandRegistry['L'] = 'goForward';
+ keyToCommandRegistry['J'] = nextTab;
+ keyToCommandRegistry['K'] = previousTab;
+
keyToCommandRegistry['t'] = createTab;
keyToCommandRegistry['d'] = removeTab;
keyToCommandRegistry['u'] = restoreTab;