aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrmr19932014-08-17 01:59:49 +0100
committermrmr19932014-08-17 02:02:33 +0100
commit13abeaebdf0bb8c5508e454ecd76275a138f5f92 (patch)
tree187d1b130ec04aea14219b1c6624e627250cdfdb
parentcda32ddd082a92ac89dc29f73f65785aff18972f (diff)
downloadvimium-13abeaebdf0bb8c5508e454ecd76275a138f5f92.tar.bz2
Add closeTabsToLeft, closeTabsToRight and closeOtherTabs commands
-rw-r--r--CREDITS1
-rw-r--r--background_scripts/commands.coffee7
-rw-r--r--background_scripts/main.coffee24
3 files changed, 31 insertions, 1 deletions
diff --git a/CREDITS b/CREDITS
index d8aee04f..60a5acaa 100644
--- a/CREDITS
+++ b/CREDITS
@@ -28,6 +28,7 @@ Contributors:
markstos
Matthew Cline <matt@nightrealms.com>
Matt Garriott (github: mgarriott)
+ Matthew Ryan (github: mrmr1993)
Michael Hauser-Raspe (github: mijoharas)
Murph (github: pandeiro)
Niklas Baumstark <niklas.baumstark@gmail.com> (github: niklasb)
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index 35c94bb9..b9586888 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -100,7 +100,8 @@ Commands =
["goBack", "goForward"]
tabManipulation:
["nextTab", "previousTab", "firstTab", "lastTab", "createTab", "duplicateTab", "removeTab",
- "restoreTab", "moveTabToNewWindow", "togglePinTab", "moveTabLeft", "moveTabRight"]
+ "restoreTab", "moveTabToNewWindow", "togglePinTab", "closeTabsToLeft","closeTabsToRight",
+ "closeOtherTabs", "moveTabLeft", "moveTabRight"]
misc:
["showHelp"]
@@ -253,6 +254,10 @@ commandDescriptions =
moveTabToNewWindow: ["Move tab to new window", { background: true }]
togglePinTab: ["Pin/unpin current tab", { background: true }]
+ closeTabsToLeft: ["Close tabs to the left", {background: true, noRepeat: true}]
+ closeTabsToRight: ["Close tabs to the right", {background: true, noRepeat: true}]
+ closeOtherTabs: ["Close other tabs", {background: true, noRepeat: true}]
+
moveTabLeft: ["Move tab to the left", { background: true, passCountToFunction: true }]
moveTabRight: ["Move tab to the right", { background: true, passCountToFunction: true }]
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) ->