diff options
| author | Stephen Blott | 2018-08-17 14:43:54 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2018-08-17 14:43:54 +0100 | 
| commit | 73dfd9f276579c28c3f93033e12f0a24e8103af6 (patch) | |
| tree | c6851cc9bc62a6a0778befbe3f0f8ea4dfcf8c2a /background_scripts | |
| parent | db3c4820fc826ed13e70aab3acee325dfe907f09 (diff) | |
| download | vimium-73dfd9f276579c28c3f93033e12f0a24e8103af6.tar.bz2 | |
Refactor...
Refactor code for selecting the tabs to which a tab command with a count
prefic should apply.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/main.coffee | 12 | 
1 files changed, 7 insertions, 5 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index e0215436..295c9d25 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -214,11 +214,7 @@ BackgroundCommands =    previousTab: (request) -> selectTab "previous", request    firstTab: (request) -> selectTab "first", request    lastTab: (request) -> selectTab "last", request -  removeTab: ({count, tab}) -> -    chrome.tabs.query {currentWindow: true}, (tabs) -> -      activeTabIndex = tab.index -      startTabIndex = Math.max 0, Math.min activeTabIndex, tabs.length - count -      chrome.tabs.remove (tab.id for tab in tabs[startTabIndex...startTabIndex + count]) +  removeTab: ({count, tab}) -> forCountTabs count, tab, (tab) -> chrome.tabs.remove tab.id    restoreTab: mkRepeatCommand (request, callback) -> chrome.sessions.restore null, callback request    togglePinTab: ({tab}) -> chrome.tabs.update tab.id, {pinned: !tab.pinned}    toggleMuteTab: toggleMuteTab @@ -244,6 +240,12 @@ BackgroundCommands =        count = Math.min count, tabs.length        chrome.tabs.reload tab.id, {bypassCache} for tab in tabs[...count] +forCountTabs = (count, currentTab, callback) -> +  chrome.tabs.query {currentWindow: true}, (tabs) -> +    activeTabIndex = currentTab.index +    startTabIndex = Math.max 0, Math.min activeTabIndex, tabs.length - count +    callback tab for tab in tabs[startTabIndex...startTabIndex + count] +  # Remove tabs before, after, or either side of the currently active tab  removeTabsRelative = (direction, {tab: activeTab}) ->    chrome.tabs.query {currentWindow: true}, (tabs) -> | 
