Bug 1422211 - Do not try to move a tab when it is the only tab in a window, r?mixedpuppy draft
authorBob Silverberg <bsilverberg@mozilla.com>
Fri, 01 Dec 2017 09:03:44 -0500
changeset 706224 82e6eea6f75656ad052338e8f1993b87061c8b3e
parent 706205 781485c695e1f07b8782427d556f6570e4a8072f
child 742605 c3fb19b1722af9a3d6a2054c5d067952b9cd5eac
push id91739
push userbmo:bob.silverberg@gmail.com
push dateFri, 01 Dec 2017 14:06:04 +0000
reviewersmixedpuppy
bugs1422211
milestone59.0a1
Bug 1422211 - Do not try to move a tab when it is the only tab in a window, r?mixedpuppy The problem reported in this bug is that the newTab button moves to an invalid position when there's only 1 tab in a window and you try to move it to the end of the tab strip via tabs.move. This may be caused by a bug in tabbrowser, which is being investigated separately, but it brought to light the fact that we're trying to move a tab when it's the only tab in a window, and that just doesn't make sense. This patch updates the code so we don't try to move a tab if it's the only tab in the window. MozReview-Commit-ID: 1oBs0OHnvxi
browser/components/extensions/ext-tabs.js
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -612,16 +612,22 @@ this.tabs = class extends ExtensionAPI {
           let lastInsertion = new Map();
 
           let tabs = tabIds.map(tabId => tabTracker.getTab(tabId));
           for (let nativeTab of tabs) {
             // If the window is not specified, use the window from the tab.
             let window = destinationWindow || nativeTab.ownerGlobal;
             let gBrowser = window.gBrowser;
 
+            // If we are not moving the tab to a different window, and the window
+            // only has one tab, do nothing.
+            if (nativeTab.ownerGlobal == window && gBrowser.tabs.length === 1) {
+              continue;
+            }
+
             let insertionPoint = indexMap.get(window) || moveProperties.index;
             // If the index is -1 it should go to the end of the tabs.
             if (insertionPoint == -1) {
               insertionPoint = gBrowser.tabs.length;
             }
 
             // We can only move pinned tabs to a point within, or just after,
             // the current set of pinned tabs. Unpinned tabs, likewise, can only