mirror of
https://github.com/tridactyl/tridactyl.git
synced 2026-09-10 07:16:33 -04:00
3
Move tab to another window and focus it
Gold Holk edited this page 2022-07-21 11:52:01 +08:00
:tabpush can move tab to another window, but you will focus to another tab in origin window.
This script will call pushtab and focus the moved tab in another window in little delay:
command tabpush_and_focus jsb void async function(){const tab=await activeTab();const tabId=tab.id;const oldWindowId=tab.windowId;fillcmdline("tabpush");await new Promise(ok=>{browser.tabs.onActivated.addListener(function leftCurrentTab(event){browser.tabs.onActivated.removeListener(leftCurrentTab);ok()})});const tabNow=await browser.tabs.get(tabId);if(tabNow.windowId==oldWindowId)return;browser.tabs.update(tabId,{active:true});browser.windows.update(tabNow.windowId,{focused:true})}();
This will execute tabpush and open a completion dialog.
Origin code:
void async function () {
const tab = await activeTab()
const tabId = tab.id
const oldWindowId = tab.windowId
fillcmdline("tabpush")
await new Promise(ok => {
browser.tabs.onActivated.addListener(function leftCurrentTab(event) {
browser.tabs.onActivated.removeListener(leftCurrentTab)
ok()
})
})
const tabNow = await browser.tabs.get(tabId)
if (tabNow.windowId == oldWindowId) return
browser.tabs.update(tabId, {active:true})
browser.windows.update(tabNow.windowId, {focused:true})
}()