diff options
| author | Stephen Blott | 2016-02-09 15:55:49 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-02-09 15:55:52 +0000 | 
| commit | 60d33d20026cdcdd0c4ecef20410d38341c86633 (patch) | |
| tree | cd9c40694ad4fadd039e143685e33be49b45610d | |
| parent | 4ada22e85dcd061fa806a5fe72a9dc3f1cfe0442 (diff) | |
| download | vimium-60d33d20026cdcdd0c4ecef20410d38341c86633.tar.bz2 | |
BgUtils; implement visitPreviousTab.
Implements visitPreviousTab (as discussed in #1955).
| -rw-r--r-- | background_scripts/bg_utils.coffee | 7 | ||||
| -rw-r--r-- | background_scripts/commands.coffee | 3 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 5 | 
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) -> | 
