Skip to content

Commit

Permalink
Move tabs across windows with their tree structure more safely #2546
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 4, 2020
1 parent f453299 commit 88cc871
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion webextensions/background/api-tabs-listener.js
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions webextensions/background/handle-new-tabs.js
Expand Up @@ -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
});
}
}
});

0 comments on commit 88cc871

Please sign in to comment.