aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-02-20 12:10:55 +0000
committerStephen Blott2016-02-20 12:10:55 +0000
commit85c3fd9a6b5a22703195738b101bf17b24c8fba9 (patch)
treeedf9f70ea0e7a6b36db1b46e3501e61372311de7
parent2debf3e07ecc41e8d0c3c186f4d8ae39641426f4 (diff)
parent1795d5a50531f7d090375ea6078ad6e0d59830fe (diff)
downloadvimium-85c3fd9a6b5a22703195738b101bf17b24c8fba9.tar.bz2
Merge pull request #2003 from smblott-github/count-for-new-window
Make `moveToNewWindow` accept a count.
-rw-r--r--background_scripts/commands.coffee2
-rw-r--r--background_scripts/main.coffee12
2 files changed, 9 insertions, 5 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index d251c7ed..01eecd81 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -344,7 +344,7 @@ commandDescriptions =
(if chrome.session then chrome.session.MAX_SESSION_RESULTS else 25) }]
restoreTab: ["Restore closed tab", { background: true, repeatLimit: 20 }]
- moveTabToNewWindow: ["Move tab to new window", { background: true }]
+ moveTabToNewWindow: ["Move tab to new window", { background: true, passCountToFunction: true }]
togglePinTab: ["Pin/unpin current tab", { background: true }]
closeTabsOnLeft: ["Close tabs on the left", {background: true, noRepeat: true}]
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 0e043159..d5b14d4f 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -275,10 +275,14 @@ BackgroundCommands =
chrome.tabs.getSelected(null, (tab) ->
chrome.tabs.duplicate(tab.id)
selectionChangedHandlers.push(callback))
- moveTabToNewWindow: (callback) ->
- chrome.tabs.query {active: true, currentWindow: true}, (tabs) ->
- tab = tabs[0]
- chrome.windows.create {tabId: tab.id, incognito: tab.incognito}
+ moveTabToNewWindow: (count) ->
+ chrome.tabs.query {currentWindow: true}, (tabs) ->
+ chrome.tabs.query {currentWindow: true, active: true}, (activeTabs) ->
+ activeTabIndex = activeTabs[0].index
+ startTabIndex = Math.max 0, Math.min activeTabIndex, tabs.length - count
+ [ tab, tabs... ] = tabs[startTabIndex...startTabIndex + count]
+ chrome.windows.create {tabId: tab.id, incognito: tab.incognito}, (window) ->
+ chrome.tabs.move (tab.id for tab in tabs), {windowId: window.id, index: -1}
nextTab: (count) -> selectTab "next", count
previousTab: (count) -> selectTab "previous", count
firstTab: (count) -> selectTab "first", count