diff options
| author | Phil Crosby | 2014-08-17 11:13:55 -0700 |
|---|---|---|
| committer | Phil Crosby | 2014-08-17 11:13:55 -0700 |
| commit | 64d4ecbf1985afa4fd9d6adec10d66b51f1f4d7f (patch) | |
| tree | 66e4d2fa70a3fb92971f356b8f75c23fd77d546c /background_scripts/main.coffee | |
| parent | 328ebe9f0c49f0d48cff07280ee7bd8da21d3476 (diff) | |
| parent | 13abeaebdf0bb8c5508e454ecd76275a138f5f92 (diff) | |
| download | vimium-64d4ecbf1985afa4fd9d6adec10d66b51f1f4d7f.tar.bz2 | |
Merge pull request #1129 from mrmr1993/closeOtherTabs
Add closeTabsToLeft, closeTabsToRight and closeOtherTabs commands
Diffstat (limited to 'background_scripts/main.coffee')
| -rw-r--r-- | background_scripts/main.coffee | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 93ef1449..a8f851c0 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -290,6 +290,30 @@ BackgroundCommands = chrome.tabs.sendMessage(tab.id, { name: "focusFrame", frameId: frames[newIndex].id, highlight: true })) + closeTabsToLeft: -> removeTabsRelative "before" + closeTabsToRight: -> removeTabsRelative "after" + closeOtherTabs: -> removeTabsRelative "both" + +# Remove tabs before, after, or either side of the currently active tab +removeTabsRelative = (direction) -> + chrome.tabs.query {currentWindow: true}, (tabs) -> + chrome.tabs.query {currentWindow: true, active: true}, (activeTabArr) -> + activeTabIndex = activeTabArr[0].index + + switch direction + when "before" + shouldDelete = (index) -> index < activeTabIndex + when "after" + shouldDelete = (index) -> index > activeTabIndex + when "both" + shouldDelete = (index) -> index != activeTabIndex + + removeTabIds = [] + for tab in tabs + if not tab.pinned and shouldDelete tab.index + removeTabIds.push tab.id + chrome.tabs.remove removeTabIds + # Selects a tab before or after the currently selected tab. # - direction: "next", "previous", "first" or "last". selectTab = (callback, direction) -> |
