aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/bg_utils.coffee9
-rw-r--r--background_scripts/main.coffee5
2 files changed, 7 insertions, 7 deletions
diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee
index bd00fd24..96c1282a 100644
--- a/background_scripts/bg_utils.coffee
+++ b/background_scripts/bg_utils.coffee
@@ -39,12 +39,11 @@ 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)
+ # Returns a list of tab Ids sorted by recency, most recent tab first.
+ getTabsByRecency: ->
+ tabIds = (tId for own tId of @cache)
tabIds.sort (a,b) => @cache[b] - @cache[a]
- parseInt tabIds[(count-1)%tabIds.length]
+ tabIds.map (tId) -> parseInt tId
BgUtils =
tabRecency: new TabRecency()
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 972f1529..a1311a46 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -337,8 +337,9 @@ BackgroundCommands =
visitPreviousTab: (count) ->
chrome.tabs.getSelected null, (tab) ->
- newTabId = BgUtils.tabRecency.getRecentTab tab.id, count
- chrome.tabs.update newTabId, selected: true
+ tabIds = BgUtils.tabRecency.getTabsByRecency().filter (tabId) -> tabId != tab.id
+ if 0 < tabIds.length
+ selectSpecificTab id: tabIds[(count-1) % tabIds.length]
# Remove tabs before, after, or either side of the currently active tab
removeTabsRelative = (direction) ->