diff options
| author | Stephen Blott | 2016-02-21 06:50:48 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-02-21 06:50:48 +0000 |
| commit | c4af8a5fb217f50e3089f0f01d3a18d7d2155848 (patch) | |
| tree | ed40587fd985656dda607a72b49474c7e15fa8de | |
| parent | 636964735bc8e9f1b802dc392b628e5ff92d319f (diff) | |
| parent | eaafbbeeab7181ae1d3da3aa9495f98b593798f9 (diff) | |
| download | vimium-c4af8a5fb217f50e3089f0f01d3a18d7d2155848.tar.bz2 | |
Merge pull request #2006 from smblott-github/fix-removeTab
Fix `<count>removeTab`.
| -rw-r--r-- | background_scripts/commands.coffee | 2 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 684f726e..4e8c48ca 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -339,7 +339,7 @@ commandDescriptions = createTab: ["Create new tab", { background: true, repeatLimit: 20 }] duplicateTab: ["Duplicate current tab", { background: true, repeatLimit: 20 }] - removeTab: ["Close current tab", { background: true, repeatLimit: + removeTab: ["Close current tab", { background: true, passCountToFunction: true, repeatLimit: # Require confirmation to remove more tabs than we can restore. (if chrome.session then chrome.session.MAX_SESSION_RESULTS else 25) }] restoreTab: ["Restore closed tab", { background: true, repeatLimit: 20 }] diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 3498cf76..3eb8ef76 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -286,10 +286,12 @@ BackgroundCommands = previousTab: (count) -> selectTab "previous", count firstTab: (count) -> selectTab "first", count lastTab: (count) -> selectTab "last", count - removeTab: (callback) -> - chrome.tabs.getSelected(null, (tab) -> - chrome.tabs.remove(tab.id) - selectionChangedHandlers.push(callback)) + removeTab: (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 + chrome.tabs.remove (tab.id for tab in tabs[startTabIndex...startTabIndex + count]) restoreTab: (callback) -> chrome.sessions.restore null, -> callback() unless chrome.runtime.lastError |
