diff --git a/modules/browser.js b/modules/browser.js index ccb5d894..199bacdd 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -6531,15 +6531,16 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { if (aOptions.duplicate) { aTab = this.duplicateTabAsOrphan(aTab); - let promise = new Promise(function(aResolve, aReject) { + aTab.__treestyletab__promisedDuplicatedTab = new Promise(function(aResolve, aReject) { let onTabRestoring = function() { aTab.removeEventListener('SSTabRestoring', onTabRestoring, false); + delete aTab.__treestyletab__promisedDuplicatedTab; aResolve(aTab); }; aTab.addEventListener('SSTabRestoring', onTabRestoring, false); }); newTabs.push(aTab); - promisedDuplicatedTabs.push(promise); + promisedDuplicatedTabs.push(aTab.__treestyletab__promisedDuplicatedTab); } else if (sourceService != this) { aTab = this.importTab(aTab); diff --git a/modules/tabbarDNDObserver.js b/modules/tabbarDNDObserver.js index 36b09c11..9b5d1496 100644 --- a/modules/tabbarDNDObserver.js +++ b/modules/tabbarDNDObserver.js @@ -598,13 +598,17 @@ catch(e) { }).bind(this), 0); if (newTabs.length && aInfo.action & sv.kACTION_ATTACH) { + Promise.all(newTabs.map((aTab) => aTab.__treestyletab__promisedDuplicatedTab)) + .then((function() { log(' => attach (last)'); this.attachTabsOnDrop( newTabs.filter(function(aTab, aIndex) { return treeStructure[aIndex] == -1; }), - aInfo.parent + aInfo.parent, + aInfo.insertBefore ); + }).bind(this)); } log(' => finished'); @@ -647,7 +651,7 @@ catch(e) { }; }, - attachTabsOnDrop : function TabbarDND_attachTabsOnDrop(aTabs, aParent) + attachTabsOnDrop : function TabbarDND_attachTabsOnDrop(aTabs, aParent, aInsertBefore) { log('attachTabsOnDrop: start'); var b = aTabs[0].ownerDocument.defaultView.TreeStyleTabService.getTabBrowserFromChild(aTabs[0]); @@ -659,7 +663,9 @@ catch(e) { let tab = aTabs[i]; if (!tab.parentNode) continue; // ignore removed tabs if (aParent) - sv.attachTabTo(tab, aParent); + sv.attachTabTo(tab, aParent, { + insertBefore : aInsertBefore + }); else sv.detachTab(tab); sv.collapseExpandTab(tab, false);