feat: Close tab and switch to recent tab when going back with no history, p=#11190

Co-authored-by: mr. m <91018726+mr-cheffy@users.noreply.github.com>
This commit is contained in:
Kyle Kincer
2025-11-09 12:32:13 -05:00
committed by GitHub
parent c382001253
commit 421adade52
7 changed files with 72 additions and 10 deletions

View File

@@ -56,6 +56,9 @@ pane-settings-workspaces-title = Workspaces
zen-tabs-unloader-enabled =
.label = Enable Tab Unloader
zen-tabs-close-on-back-with-no-history =
.label = Close tab and switch to its owner tab (or most recently used tab) when going back with no history
zen-look-and-feel-compact-toolbar-themed =
.label = Use themed background for compact toolbar

View File

@@ -34,3 +34,6 @@
- name: zen.tabs.open-pinned-in-new-tab
value: true
- name: zen.tabs.close-on-back-with-no-history
value: true

View File

@@ -1,8 +1,19 @@
diff --git a/browser/base/content/browser-commands.js b/browser/base/content/browser-commands.js
index 939ca497b882b3f4200141ba1b6764fb5c846f45..36c830a503b004c0a332340f686c86cad68e9381 100644
index 939ca497b882b3f4200141ba1b6764fb5c846f45..779cba5ff3df856a246321a36caa3725c054a314 100644
--- a/browser/base/content/browser-commands.js
+++ b/browser/base/content/browser-commands.js
@@ -315,6 +315,10 @@ var BrowserCommands = {
@@ -14,6 +14,10 @@ var BrowserCommands = {
const where = BrowserUtils.whereToOpenLink(aEvent, false, true);
if (where == "current") {
+ if (!gBrowser.webNavigation.canGoBack && gZenCommonActions.shouldCloseTabOnBack()) {
+ gBrowser.removeTab(gBrowser.selectedTab);
+ return;
+ }
try {
gBrowser.goBack();
} catch (ex) {}
@@ -315,6 +319,10 @@ var BrowserCommands = {
}
}
@@ -13,7 +24,7 @@ index 939ca497b882b3f4200141ba1b6764fb5c846f45..36c830a503b004c0a332340f686c86ca
// A notification intended to be useful for modular peformance tracking
// starting as close as is reasonably possible to the time when the user
// expressed the intent to open a new tab. Since there are a lot of
@@ -399,6 +403,11 @@ var BrowserCommands = {
@@ -399,6 +407,11 @@ var BrowserCommands = {
return;
}
@@ -25,7 +36,7 @@ index 939ca497b882b3f4200141ba1b6764fb5c846f45..36c830a503b004c0a332340f686c86ca
// Keyboard shortcuts that would close a tab that is pinned select the first
// unpinned tab instead.
if (
@@ -406,8 +415,8 @@ var BrowserCommands = {
@@ -406,8 +419,8 @@ var BrowserCommands = {
(event.ctrlKey || event.metaKey || event.altKey) &&
gBrowser.selectedTab.pinned
) {

View File

@@ -0,0 +1,13 @@
diff --git a/browser/base/content/browser-gestureSupport.js b/browser/base/content/browser-gestureSupport.js
index a28d54bf72c0e6495b9586f220d1859aac794936..66154668b9f85ffbaacea1e8351370659260227b 100644
--- a/browser/base/content/browser-gestureSupport.js
+++ b/browser/base/content/browser-gestureSupport.js
@@ -832,7 +832,7 @@ var gHistorySwipeAnimation = {
* @return true if there is a previous page in history, false otherwise.
*/
canGoBack: function HSA_canGoBack() {
- return gBrowser.webNavigation.canGoBack;
+ return gBrowser.webNavigation.canGoBack || gZenCommonActions.shouldCloseTabOnBack();
},
/**

View File

@@ -1,5 +1,5 @@
diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
index b4b79e7fb3228ba91bd8afa08659be0d88883725..9e1d59b6a736107e55bda73686a4a627e4c0ba7c 100644
index b4b79e7fb3228ba91bd8afa08659be0d88883725..b4801e2a3076139622d58f81943e61cd61ee1828 100644
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -31,6 +31,7 @@ ChromeUtils.defineESModuleGetters(this, {
@@ -10,7 +10,21 @@ index b4b79e7fb3228ba91bd8afa08659be0d88883725..9e1d59b6a736107e55bda73686a4a627
DevToolsSocketStatus:
"resource://devtools/shared/security/DevToolsSocketStatus.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
@@ -2298,6 +2299,8 @@ var XULBrowserWindow = {
@@ -822,7 +823,12 @@ function UpdateBackForwardCommands(aWebNavigation) {
var backDisabled = backCommand.hasAttribute("disabled");
var forwardDisabled = forwardCommand.hasAttribute("disabled");
- if (backDisabled == aWebNavigation.canGoBack) {
+ var canGoBack = aWebNavigation.canGoBack;
+ if (!canGoBack) {
+ canGoBack = gZenCommonActions.shouldCloseTabOnBack();
+ }
+
+ if (backDisabled == canGoBack) {
if (backDisabled) {
backCommand.removeAttribute("disabled");
} else {
@@ -2298,6 +2304,8 @@ var XULBrowserWindow = {
AboutReaderParent.updateReaderButton(gBrowser.selectedBrowser);
TranslationsParent.onLocationChange(gBrowser.selectedBrowser);
@@ -19,7 +33,7 @@ index b4b79e7fb3228ba91bd8afa08659be0d88883725..9e1d59b6a736107e55bda73686a4a627
PictureInPicture.updateUrlbarToggle(gBrowser.selectedBrowser);
if (!gMultiProcessBrowser) {
@@ -3809,7 +3812,7 @@ function warnAboutClosingWindow() {
@@ -3809,7 +3817,7 @@ function warnAboutClosingWindow() {
if (!isPBWindow && !toolbar.visible) {
return gBrowser.warnAboutClosingTabs(
@@ -28,7 +42,7 @@ index b4b79e7fb3228ba91bd8afa08659be0d88883725..9e1d59b6a736107e55bda73686a4a627
gBrowser.closingTabsEnum.ALL
);
}
@@ -3849,7 +3852,7 @@ function warnAboutClosingWindow() {
@@ -3849,7 +3857,7 @@ function warnAboutClosingWindow() {
return (
isPBWindow ||
gBrowser.warnAboutClosingTabs(
@@ -37,7 +51,7 @@ index b4b79e7fb3228ba91bd8afa08659be0d88883725..9e1d59b6a736107e55bda73686a4a627
gBrowser.closingTabsEnum.ALL
)
);
@@ -3874,7 +3877,7 @@ function warnAboutClosingWindow() {
@@ -3874,7 +3882,7 @@ function warnAboutClosingWindow() {
AppConstants.platform != "macosx" ||
isPBWindow ||
gBrowser.warnAboutClosingTabs(
@@ -46,7 +60,7 @@ index b4b79e7fb3228ba91bd8afa08659be0d88883725..9e1d59b6a736107e55bda73686a4a627
gBrowser.closingTabsEnum.ALL
)
);
@@ -4796,6 +4799,9 @@ var ConfirmationHint = {
@@ -4796,6 +4804,9 @@ var ConfirmationHint = {
MozXULElement.insertFTLIfNeeded("toolkit/branding/brandings.ftl");
MozXULElement.insertFTLIfNeeded("browser/confirmationHints.ftl");
document.l10n.setAttributes(this._message, messageId, options.l10nArgs);

View File

@@ -26,6 +26,9 @@
<checkbox id="zenWorkspacesForceContainerTabsToWorkspace"
data-l10n-id="zen-settings-workspaces-force-container-tabs-to-workspace"
preference="zen.workspaces.force-container-workspace"/>
<checkbox id="zenTabsCloseOnBackWithNoHistory"
data-l10n-id="zen-tabs-close-on-back-with-no-history"
preference="zen.tabs.close-on-back-with-no-history"/>
</groupbox>
<hbox id="zenTabsUnloadCategory"

View File

@@ -107,4 +107,19 @@ var gZenCommonActions = {
timer = setTimeout(() => f.apply(this, args), delay);
};
},
/**
* Determines if a tab should be closed when navigating back with no history.
* Only tabs with an owner that are not pinned and not empty are eligible.
* Respects the user preference zen.tabs.close-on-back-with-no-history.
*
* @return {boolean} True if the tab should be closed on back
*/
shouldCloseTabOnBack() {
if (!Services.prefs.getBoolPref('zen.tabs.close-on-back-with-no-history', true)) {
return false;
}
const tab = gBrowser.selectedTab;
return Boolean(tab.owner && !tab.pinned && !tab.hasAttribute('zen-empty-tab'));
},
};