Rewrite nextTab, fix multiple windows

This commit is contained in:
Oliver Blanthorn 2017-02-13 23:01:00 +00:00
parent 5951a29ce7
commit db06783c8c

View file

@ -55,15 +55,16 @@ displayTab = (tab_id) ->
browser.browserAction.onClicked.addListener(handleBrowserAction)
nextTab = () ->
browser.tabs.query({active:true}).then((tabs) ->
id = tabs[0].id
index = tabs[0].index
desIndex = index + 1
browser.tabs.query({}).then((tabs) ->
desId = tab for tab in tabs when tab.index == desIndex
setTab(desId.id)
)
)
browser.windows.getCurrent().then(
(window) ->
browser.tabs.query({windowId:window.id}).then(
(tabs) ->
active = (tab for tab in tabs when tab.active)[0]
nextIndex = (active.index + 1) % tabs.length
desiredTab = (tab for tab in tabs when tab.index == nextIndex)[0]
setTab(desiredTab.id)
).catch(console.error)
).catch(console.error)
setTab = (id) ->
browser.tabs.update(id,{active:true})