aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/bg_utils.coffee7
-rw-r--r--background_scripts/commands.coffee3
-rw-r--r--background_scripts/main.coffee5
3 files changed, 15 insertions, 0 deletions
diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee
index 9c1674bf..bd00fd24 100644
--- a/background_scripts/bg_utils.coffee
+++ b/background_scripts/bg_utils.coffee
@@ -39,6 +39,13 @@ class TabRecency
@cache[tabId] ||= 1
if tabId == @current then 0.0 else @cache[tabId] / @timestamp
+ # Get the tab Id of the count-th most recently visited tab (excluding tabId, which is the current tab).
+ getRecentTab: (tabId, count) ->
+ tabId = tabId.toString()
+ tabIds = (tId for own tId of @cache when tId != tabId)
+ tabIds.sort (a,b) => @cache[b] - @cache[a]
+ parseInt tabIds[(count-1)%tabIds.length]
+
BgUtils =
tabRecency: new TabRecency()
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index d42fd9fb..9c958461 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -125,6 +125,7 @@ Commands =
tabManipulation:
["nextTab",
"previousTab",
+ "visitPreviousTab",
"firstTab",
"lastTab",
"createTab",
@@ -215,6 +216,7 @@ defaultKeyMappings =
"J": "previousTab"
"gt": "nextTab"
"gT": "previousTab"
+ "^": "visitPreviousTab"
"<<": "moveTabLeft"
">>": "moveTabRight"
"g0": "firstTab"
@@ -306,6 +308,7 @@ commandDescriptions =
# Manipulating tabs
nextTab: ["Go one tab right", { background: true, passCountToFunction: true }]
previousTab: ["Go one tab left", { background: true, passCountToFunction: true }]
+ visitPreviousTab: ["Go to previously-visited tab", { background: true, passCountToFunction: true }]
firstTab: ["Go to the first tab", { background: true, passCountToFunction: true }]
lastTab: ["Go to the last tab", { background: true, passCountToFunction: true }]
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index ad47c399..972f1529 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -335,6 +335,11 @@ BackgroundCommands =
closeTabsOnRight: -> removeTabsRelative "after"
closeOtherTabs: -> removeTabsRelative "both"
+ visitPreviousTab: (count) ->
+ chrome.tabs.getSelected null, (tab) ->
+ newTabId = BgUtils.tabRecency.getRecentTab tab.id, count
+ chrome.tabs.update newTabId, selected: true
+
# Remove tabs before, after, or either side of the currently active tab
removeTabsRelative = (direction) ->
chrome.tabs.query {currentWindow: true}, (tabs) ->