From 88cc87130c8b3d9a32e1d9f22ba69b022d53d238 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Thu, 5 Nov 2020 04:01:38 +0900 Subject: [PATCH] Move tabs across windows with their tree structure more safely #2546 --- webextensions/background/api-tabs-listener.js | 6 +++++- webextensions/background/handle-new-tabs.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/webextensions/background/api-tabs-listener.js b/webextensions/background/api-tabs-listener.js index 113589099..797a21109 100644 --- a/webextensions/background/api-tabs-listener.js +++ b/webextensions/background/api-tabs-listener.js @@ -974,12 +974,16 @@ async function onDetached(tabId, detachInfo) { if (byInternalOperation) oldWindow.toBeDetachedTabs.delete(tabId); + const descendants = oldTab.$TST.descendants; const info = { ...detachInfo, byInternalOperation, windowId: detachInfo.oldWindowId, - descendants: oldTab.$TST.descendants + structure: TreeBehavior.getTreeStructureFromTabs([oldTab, ...descendants]), + descendants }; + const alreadyMovedAcrossWindows = Array.from(mTreeInfoForTabsMovingAcrossWindows.values(), info => info.descendants.map(tab => tab.id)).some(tabIds => tabIds.includes(tabId)); + if (!alreadyMovedAcrossWindows) mTreeInfoForTabsMovingAcrossWindows.set(tabId, info); if (!byInternalOperation) // we should process only tabs detached by others. diff --git a/webextensions/background/handle-new-tabs.js b/webextensions/background/handle-new-tabs.js index f713c2d53..d4873c30a 100644 --- a/webextensions/background/handle-new-tabs.js +++ b/webextensions/background/handle-new-tabs.js @@ -369,10 +369,18 @@ Tab.onAttached.addListener(async (tab, info = {}) => { insertAfter: tab }); log('moved descendants: ', () => movedTabs.map(dumpTab)); + if (info.descendants.length == movedTabs.length) { + await Tree.applyTreeStructureToTabs( + [tab, ...movedTabs], + info.structure + ); + } + else { for (const movedTab of movedTabs) { Tree.attachTabTo(movedTab, tab, { broadcast: true, dontMove: true }); } + } });