Bug 1419537 - Make 'Close Tabs to the Right' and 'Close Other Tabs' available on pinned tabs to close non-pinned ones. r?jaws
MozReview-Commit-ID: 3kooJBCy8du
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -8543,27 +8543,26 @@ var TabContextMenu = {
document.getElementById("context_undoCloseTab").disabled =
SessionStore.getClosedTabCount(window) == 0;
// Only one of pin/unpin should be visible
document.getElementById("context_pinTab").hidden = this.contextTab.pinned;
document.getElementById("context_unpinTab").hidden = !this.contextTab.pinned;
// Disable "Close Tabs to the Right" if there are no tabs
- // following it and hide it when the user rightclicked on a pinned
- // tab.
+ // following it.
document.getElementById("context_closeTabsToTheEnd").disabled =
gBrowser.getTabsToTheEndFrom(this.contextTab).length == 0;
- document.getElementById("context_closeTabsToTheEnd").hidden = this.contextTab.pinned;
-
- // Disable "Close other Tabs" if there is only one unpinned tab and
- // hide it when the user rightclicked on a pinned tab.
- let unpinnedTabs = gBrowser.visibleTabs.length - gBrowser._numPinnedTabs;
- document.getElementById("context_closeOtherTabs").disabled = unpinnedTabs <= 1;
- document.getElementById("context_closeOtherTabs").hidden = this.contextTab.pinned;
+
+ // Disable "Close other Tabs" if there are no unpinned tabs.
+ let unpinnedTabsToClose = gBrowser.visibleTabs.length - gBrowser._numPinnedTabs;
+ if (!this.contextTab.pinned) {
+ unpinnedTabsToClose--;
+ }
+ document.getElementById("context_closeOtherTabs").disabled = unpinnedTabsToClose < 1;
// Hide "Bookmark All Tabs" for a pinned tab. Update its state if visible.
let bookmarkAllTabs = document.getElementById("context_bookmarkAllTabs");
bookmarkAllTabs.hidden = this.contextTab.pinned;
if (!bookmarkAllTabs.hidden)
PlacesCommandHook.updateBookmarkAllTabsCommand();
// Adjust the state of the toggle mute menu item.
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2966,19 +2966,22 @@
]]>
</body>
</method>
<method name="getTabsToTheEndFrom">
<parameter name="aTab"/>
<body>
<![CDATA[
- var tabsToEnd = [];
+ let tabsToEnd = [];
let tabs = this.visibleTabs;
- for (let i = tabs.length - 1; tabs[i] != aTab && i >= 0; --i) {
+ for (let i = tabs.length - 1; i >= 0; --i) {
+ if (tabs[i] == aTab || tabs[i].pinned) {
+ break;
+ }
tabsToEnd.push(tabs[i]);
}
return tabsToEnd;
]]>
</body>
</method>
<method name="removeTabsToTheEndFrom">
@@ -3010,19 +3013,19 @@
]]>
</body>
</method>
<method name="removeAllTabsBut">
<parameter name="aTab"/>
<body>
<![CDATA[
- if (aTab.pinned ||
- !this.warnAboutClosingTabs(this.closingTabsEnum.OTHER))
+ if (!this.warnAboutClosingTabs(this.closingTabsEnum.OTHER)) {
return;
+ }
let tabs = this.visibleTabs.reverse();
this.selectedTab = aTab;
let tabsWithBeforeUnload = [];
for (let i = tabs.length - 1; i >= 0; --i) {
let tab = tabs[i];
if (tab != aTab && !tab.pinned) {
--- a/browser/base/content/test/general/browser_visibleTabs_contextMenu.js
+++ b/browser/base/content/test/general/browser_visibleTabs_contextMenu.js
@@ -27,31 +27,38 @@ add_task(async function test() {
is(document.getElementById("context_reloadAllTabs").disabled, true, "Reload All Tabs is disabled");
// Add a tab that will get pinned
// So now there's one pinned tab, one visible unpinned tab, and one hidden tab
let pinned = BrowserTestUtils.addTab(gBrowser);
gBrowser.pinTab(pinned);
is(gBrowser.visibleTabs.length, 2, "now there are two visible tabs");
+ // Check the context menu on the pinned tab
+ updateTabContextMenu(pinned);
+ ok(!document.getElementById("context_closeOtherTabs").disabled, "Close Other Tabs is enabled on pinned tab");
+ ok(!document.getElementById("context_closeTabsToTheEnd").disabled, "Close Tabs To The End is enabled on pinned tab");
+
// Check the context menu on the unpinned visible tab
updateTabContextMenu(testTab);
- is(document.getElementById("context_closeOtherTabs").disabled, true, "Close Other Tabs is disabled");
- is(document.getElementById("context_closeTabsToTheEnd").disabled, true, "Close Tabs To The End is disabled");
+ ok(document.getElementById("context_closeOtherTabs").disabled, "Close Other Tabs is disabled on single unpinned tab");
+ ok(document.getElementById("context_closeTabsToTheEnd").disabled, "Close Tabs To The End is disabled on single unpinned tab");
// Show all tabs
let allTabs = Array.from(gBrowser.tabs);
gBrowser.showOnlyTheseTabs(allTabs);
// Check the context menu now
updateTabContextMenu(testTab);
- is(document.getElementById("context_closeOtherTabs").disabled, false, "Close Other Tabs is enabled");
- is(document.getElementById("context_closeTabsToTheEnd").disabled, true, "Close Tabs To The End is disabled");
+ ok(!document.getElementById("context_closeOtherTabs").disabled,
+ "Close Other Tabs is enabled on unpinned tab when there's another unpinned tab");
+ ok(document.getElementById("context_closeTabsToTheEnd").disabled, "Close Tabs To The End is disabled on last unpinned tab");
// Check the context menu of the original tab
// Close Tabs To The End should now be enabled
updateTabContextMenu(origTab);
- is(document.getElementById("context_closeTabsToTheEnd").disabled, false, "Close Tabs To The End is enabled");
+ ok(!document.getElementById("context_closeTabsToTheEnd").disabled,
+ "Close Tabs To The End is enabled on unpinned tab when followed by another");
gBrowser.removeTab(testTab);
gBrowser.removeTab(pinned);
});