Bug 1504274 - Close Tabs to the Right in a multiselect context should close all tabs to the right of the contextual tab that are not selected. r=dao, a=jcristau
authorJared Wein <jwein@mozilla.com>
Thu, 08 Nov 2018 11:00:13 +0000
changeset 501215 b9bddcf6d4659e0c6b764de1dc6fdcc7727db3e0
parent 501214 929f848d3a54977c8b6ea468fff80954cafa6bf0
child 501216 c6949142e640b8d3727055053ee471b3eeb7d2e6
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, jcristau
bugs1504274
milestone64.0
Bug 1504274 - Close Tabs to the Right in a multiselect context should close all tabs to the right of the contextual tab that are not selected. r=dao, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D11250
browser/base/content/tabbrowser.js
browser/base/content/test/tabs/browser_multiselect_tabs_close_tabs_to_the_right.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -2647,32 +2647,27 @@ window._gBrowser = {
     // don't set the pref unless they press OK and it's false
     if (aCloseTabs == this.closingTabsEnum.ALL && reallyClose && !warnOnClose.value)
       Services.prefs.setBoolPref(pref, false);
 
     return reallyClose;
   },
 
   getTabsToTheEndFrom(aTab) {
-    let tab;
-    if (aTab.multiselected) {
-      // In a multi-select context, pick the rightmost
-      // selected tab as reference.
-      let selectedTabs = this.selectedTabs;
-      tab = selectedTabs[selectedTabs.length - 1];
-    } else {
-      tab = aTab;
-    }
-
     let tabsToEnd = [];
     let tabs = this.visibleTabs;
     for (let i = tabs.length - 1; i >= 0; --i) {
-      if (tabs[i] == tab || tabs[i].pinned) {
+      if (tabs[i] == aTab || tabs[i].pinned) {
         break;
       }
+      // In a multi-select context, select all unselected tabs
+      // starting from the context tab.
+      if (aTab.multiselected && tabs[i].multiselected) {
+        continue;
+      }
       tabsToEnd.push(tabs[i]);
     }
     return tabsToEnd;
   },
 
   /**
    * In a multi-select context, the tabs (except pinned tabs) that are located to the
    * right of the rightmost selected tab will be removed.
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_close_tabs_to_the_right.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_close_tabs_to_the_right.js
@@ -24,30 +24,31 @@ add_task(async function withAMultiSelect
 
   ok(tab1.multiselected, "Tab1 is multiselected");
   ok(!tab2.multiselected, "Tab2 is not multiselected");
   ok(tab3.multiselected, "Tab3 is multiselected");
   ok(!tab4.multiselected, "Tab4 is not multiselected");
   ok(!tab5.multiselected, "Tab5 is not multiselected");
   is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
 
-  let closingTabs = [tab4, tab5];
+  // Tab2 will be closed because tab1 is the contextTab.
+  let closingTabs = [tab2, tab4, tab5];
   let tabClosingPromises = [];
   for (let tab of closingTabs) {
     tabClosingPromises.push(BrowserTestUtils.waitForTabClosing(tab));
   }
 
   gBrowser.removeTabsToTheEndFrom(tab1);
 
   for (let promise of tabClosingPromises) {
     await promise;
   }
 
   ok(!tab1.closing, "Tab1 is not closing");
-  ok(!tab2.closing, "Tab2 is not closing");
+  ok(tab2.closing, "Tab2 is closing");
   ok(!tab3.closing, "Tab3 is not closing");
   ok(tab4.closing, "Tab4 is closing");
   ok(tab5.closing, "Tab5 is closing");
   is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
 
   for (let tab of [tab1, tab2, tab3])
     BrowserTestUtils.removeTab(tab);
 });