From 1d809afe18d8638b899a1016d9cca0ccc4a32253 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 10 Feb 2016 06:26:55 +0000 Subject: BgUtils; two fixes... - handle case where there's only one tab - also focus the selected tab's window --- background_scripts/bg_utils.coffee | 9 ++++----- background_scripts/main.coffee | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'background_scripts') 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) -> -- cgit v1.2.3