diff options
| author | Stephen Blott | 2016-02-10 06:26:55 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-02-10 06:26:55 +0000 | 
| commit | 1d809afe18d8638b899a1016d9cca0ccc4a32253 (patch) | |
| tree | f704f73fd00b0e0b323cefbda45f06f8bd55f8c6 /background_scripts | |
| parent | 60d33d20026cdcdd0c4ecef20410d38341c86633 (diff) | |
| download | vimium-1d809afe18d8638b899a1016d9cca0ccc4a32253.tar.bz2 | |
BgUtils; two fixes...
- handle case where there's only one tab
- also focus the selected tab's window
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/bg_utils.coffee | 9 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 5 | 
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) -> | 
