fix: Fixed essentials being ignored when closing tabs, b=closes #6968, c=workspaces

This commit is contained in:
mr. m
2025-09-27 12:02:47 +02:00
parent b3d981c585
commit bb33bbcc39
2 changed files with 39 additions and 74 deletions

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c1ee4358d 100644 index 3204f253c23551650991d3385dd256d55892a012..7c30015ac4591fdb97426521ae87b80ed9d2317a 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js --- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -427,15 +427,64 @@ @@ -427,15 +427,64 @@
@@ -128,22 +128,6 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
let browser = this.getBrowserForTab(aTab); let browser = this.getBrowserForTab(aTab);
browser.mIconURL = aIconURL; browser.mIconURL = aIconURL;
@@ -1249,13 +1312,13 @@
let oldTab = this.selectedTab;
// Preview mode should not reset the owner
- if (!this._previewMode && !oldTab.selected) {
+ if (!this._previewMode && !oldTab.selected && oldTab.owner && !oldTab.hasAttribute("zen-essential")) {
oldTab.owner = null;
}
let lastRelatedTab = this._lastRelatedTabMap.get(oldTab);
if (lastRelatedTab) {
- if (!lastRelatedTab.selected) {
+ if (!lastRelatedTab.selected && lastRelatedTab.owner && !lastRelatedTab.hasAttribute("zen-essential")) {
lastRelatedTab.owner = null;
}
}
@@ -1333,6 +1396,7 @@ @@ -1333,6 +1396,7 @@
if (!this._previewMode) { if (!this._previewMode) {
newTab.recordTimeFromUnloadToReload(); newTab.recordTimeFromUnloadToReload();
@@ -249,15 +233,6 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (!UserInteraction.running("browser.tabs.opening", window)) { if (!UserInteraction.running("browser.tabs.opening", window)) {
UserInteraction.start("browser.tabs.opening", "initting", window); UserInteraction.start("browser.tabs.opening", "initting", window);
} }
@@ -2752,7 +2827,7 @@
ownerTab ??= inBackground ? null : this.selectedTab;
// if we're adding tabs, we're past interrupt mode, ditch the owner
- if (this.selectedTab.owner) {
+ if (this.selectedTab.owner && !this.selectedTab.hasAttribute("zen-essential")) {
this.selectedTab.owner = null;
}
@@ -2807,6 +2882,19 @@ @@ -2807,6 +2882,19 @@
noInitialLabel, noInitialLabel,
skipBackgroundNotify, skipBackgroundNotify,
@@ -453,7 +428,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
tabGroup = previousTab.group; tabGroup = previousTab.group;
} }
if ( if (
@@ -3975,13 +4101,15 @@ @@ -3975,7 +4101,7 @@
) { ) {
elementIndex = Infinity; elementIndex = Infinity;
} else if (previousTab.visible) { } else if (previousTab.visible) {
@@ -462,16 +437,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} else if (previousTab == FirefoxViewHandler.tab) { } else if (previousTab == FirefoxViewHandler.tab) {
elementIndex = 0; elementIndex = 0;
} }
@@ -4003,14 +4129,14 @@
if (lastRelatedTab) {
- lastRelatedTab.owner = null;
+ if (!lastRelatedTab.hasAttribute("zen-essential")) {
+ lastRelatedTab.owner = null;
+ }
} else if (openerTab) {
tab.owner = openerTab;
}
@@ -4003,14 +4131,14 @@
} }
// Ensure index is within bounds. // Ensure index is within bounds.
if (tab.pinned) { if (tab.pinned) {
@@ -490,7 +456,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (pinned && !itemAfter?.pinned) { if (pinned && !itemAfter?.pinned) {
itemAfter = null; itemAfter = null;
@@ -4021,7 +4149,7 @@ @@ -4021,7 +4147,7 @@
this.tabContainer._invalidateCachedTabs(); this.tabContainer._invalidateCachedTabs();
@@ -499,7 +465,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { if (this.isTab(itemAfter) && itemAfter.group == tabGroup) {
// Place at the front of, or between tabs in, the same tab group // Place at the front of, or between tabs in, the same tab group
this.tabContainer.insertBefore(tab, itemAfter); this.tabContainer.insertBefore(tab, itemAfter);
@@ -4057,6 +4185,7 @@ @@ -4057,6 +4183,7 @@
if (pinned) { if (pinned) {
this._updateTabBarForPinnedTabs(); this._updateTabBarForPinnedTabs();
} }
@@ -507,7 +473,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
TabBarVisibility.update(); TabBarVisibility.update();
} }
@@ -4346,6 +4475,9 @@ @@ -4346,6 +4473,9 @@
return; return;
} }
@@ -517,7 +483,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
this.removeTabs(selectedTabs, { isUserTriggered, telemetrySource }); this.removeTabs(selectedTabs, { isUserTriggered, telemetrySource });
} }
@@ -4607,6 +4739,7 @@ @@ -4607,6 +4737,7 @@
telemetrySource, telemetrySource,
} = {} } = {}
) { ) {
@@ -525,7 +491,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
// When 'closeWindowWithLastTab' pref is enabled, closing all tabs // When 'closeWindowWithLastTab' pref is enabled, closing all tabs
// can be considered equivalent to closing the window. // can be considered equivalent to closing the window.
if ( if (
@@ -4696,6 +4829,7 @@ @@ -4696,6 +4827,7 @@
if (lastToClose) { if (lastToClose) {
this.removeTab(lastToClose, aParams); this.removeTab(lastToClose, aParams);
} }
@@ -533,7 +499,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@@ -4734,6 +4868,12 @@ @@ -4734,6 +4866,12 @@
aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start();
} }
@@ -546,7 +512,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
// Handle requests for synchronously removing an already // Handle requests for synchronously removing an already
// asynchronously closing tab. // asynchronously closing tab.
if (!animate && aTab.closing) { if (!animate && aTab.closing) {
@@ -4748,6 +4888,9 @@ @@ -4748,6 +4886,9 @@
// state). // state).
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
let isLastTab = this.#isLastTabInWindow(aTab); let isLastTab = this.#isLastTabInWindow(aTab);
@@ -556,7 +522,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if ( if (
!this._beginRemoveTab(aTab, { !this._beginRemoveTab(aTab, {
closeWindowFastpath: true, closeWindowFastpath: true,
@@ -4796,7 +4939,13 @@ @@ -4796,7 +4937,13 @@
// We're not animating, so we can cancel the animation stopwatch. // We're not animating, so we can cancel the animation stopwatch.
Glean.browserTabclose.timeAnim.cancel(aTab._closeTimeAnimTimerId); Glean.browserTabclose.timeAnim.cancel(aTab._closeTimeAnimTimerId);
aTab._closeTimeAnimTimerId = null; aTab._closeTimeAnimTimerId = null;
@@ -571,7 +537,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
return; return;
} }
@@ -4930,7 +5079,7 @@ @@ -4930,7 +5077,7 @@
closeWindowWithLastTab != null closeWindowWithLastTab != null
? closeWindowWithLastTab ? closeWindowWithLastTab
: !window.toolbar.visible || : !window.toolbar.visible ||
@@ -580,7 +546,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (closeWindow) { if (closeWindow) {
// We've already called beforeunload on all the relevant tabs if we get here, // We've already called beforeunload on all the relevant tabs if we get here,
@@ -4954,6 +5103,7 @@ @@ -4954,6 +5101,7 @@
newTab = true; newTab = true;
} }
@@ -588,7 +554,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
aTab._endRemoveArgs = [closeWindow, newTab]; aTab._endRemoveArgs = [closeWindow, newTab];
// swapBrowsersAndCloseOther will take care of closing the window without animation. // swapBrowsersAndCloseOther will take care of closing the window without animation.
@@ -4994,13 +5144,7 @@ @@ -4994,13 +5142,7 @@
aTab._mouseleave(); aTab._mouseleave();
if (newTab) { if (newTab) {
@@ -603,7 +569,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} else { } else {
TabBarVisibility.update(); TabBarVisibility.update();
} }
@@ -5133,6 +5277,7 @@ @@ -5133,6 +5275,7 @@
this.tabs[i]._tPos = i; this.tabs[i]._tPos = i;
} }
@@ -611,7 +577,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (!this._windowIsClosing) { if (!this._windowIsClosing) {
// update tab close buttons state // update tab close buttons state
this.tabContainer._updateCloseButtons(); this.tabContainer._updateCloseButtons();
@@ -5345,6 +5490,7 @@ @@ -5345,6 +5488,7 @@
} }
let excludeTabs = new Set(aExcludeTabs); let excludeTabs = new Set(aExcludeTabs);
@@ -619,7 +585,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
// If this tab has a successor, it should be selectable, since // If this tab has a successor, it should be selectable, since
// hiding or closing a tab removes that tab as a successor. // hiding or closing a tab removes that tab as a successor.
@@ -5357,13 +5503,13 @@ @@ -5357,13 +5501,13 @@
!excludeTabs.has(aTab.owner) && !excludeTabs.has(aTab.owner) &&
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
) { ) {
@@ -635,7 +601,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
); );
let tab = this.tabContainer.findNextTab(aTab, { let tab = this.tabContainer.findNextTab(aTab, {
@@ -5379,7 +5525,7 @@ @@ -5379,7 +5523,7 @@
} }
if (tab) { if (tab) {
@@ -644,7 +610,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} }
// If no qualifying visible tab was found, see if there is a tab in // If no qualifying visible tab was found, see if there is a tab in
@@ -5400,7 +5546,7 @@ @@ -5400,7 +5544,7 @@
}); });
} }
@@ -653,7 +619,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} }
_blurTab(aTab) { _blurTab(aTab) {
@@ -5802,10 +5948,10 @@ @@ -5802,10 +5946,10 @@
SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
} }
@@ -666,7 +632,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
aTab.selected || aTab.selected ||
aTab.closing || aTab.closing ||
// Tabs that are sharing the screen, microphone or camera cannot be hidden. // Tabs that are sharing the screen, microphone or camera cannot be hidden.
@@ -5864,6 +6010,7 @@ @@ -5864,6 +6008,7 @@
* @param {MozTabbrowserTab|MozTabbrowserTabGroup|MozTabbrowserTabGroup.labelElement} aTab * @param {MozTabbrowserTab|MozTabbrowserTabGroup|MozTabbrowserTabGroup.labelElement} aTab
*/ */
replaceTabWithWindow(aTab, aOptions) { replaceTabWithWindow(aTab, aOptions) {
@@ -674,7 +640,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (this.tabs.length == 1) { if (this.tabs.length == 1) {
return null; return null;
} }
@@ -5997,7 +6144,7 @@ @@ -5997,7 +6142,7 @@
* `true` if element is a `<tab-group>` * `true` if element is a `<tab-group>`
*/ */
isTabGroup(element) { isTabGroup(element) {
@@ -683,7 +649,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} }
/** /**
@@ -6073,8 +6220,8 @@ @@ -6073,8 +6218,8 @@
} }
// Don't allow mixing pinned and unpinned tabs. // Don't allow mixing pinned and unpinned tabs.
@@ -694,7 +660,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} else { } else {
tabIndex = Math.max(tabIndex, this.pinnedTabCount); tabIndex = Math.max(tabIndex, this.pinnedTabCount);
} }
@@ -6100,10 +6247,16 @@ @@ -6100,10 +6245,16 @@
this.#handleTabMove( this.#handleTabMove(
element, element,
() => { () => {
@@ -713,7 +679,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
if (neighbor && this.isTab(element) && tabIndex > element._tPos) { if (neighbor && this.isTab(element) && tabIndex > element._tPos) {
neighbor.after(element); neighbor.after(element);
} else { } else {
@@ -6161,23 +6314,28 @@ @@ -6161,23 +6312,28 @@
#moveTabNextTo(element, targetElement, moveBefore = false, metricsContext) { #moveTabNextTo(element, targetElement, moveBefore = false, metricsContext) {
if (this.isTabGroupLabel(targetElement)) { if (this.isTabGroupLabel(targetElement)) {
targetElement = targetElement.group; targetElement = targetElement.group;
@@ -748,7 +714,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} else if (!element.pinned && targetElement && targetElement.pinned) { } else if (!element.pinned && targetElement && targetElement.pinned) {
// If the caller asks to move an unpinned element next to a pinned // If the caller asks to move an unpinned element next to a pinned
// tab, move the unpinned element to be the first unpinned element // tab, move the unpinned element to be the first unpinned element
@@ -6190,14 +6348,34 @@ @@ -6190,14 +6346,34 @@
// move the tab group right before the first unpinned tab. // move the tab group right before the first unpinned tab.
// 4. Moving a tab group and the first unpinned tab is grouped: // 4. Moving a tab group and the first unpinned tab is grouped:
// move the tab group right before the first unpinned tab's tab group. // move the tab group right before the first unpinned tab's tab group.
@@ -784,7 +750,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
element.pinned element.pinned
? this.tabContainer.pinnedTabsContainer ? this.tabContainer.pinnedTabsContainer
: this.tabContainer; : this.tabContainer;
@@ -6206,7 +6384,7 @@ @@ -6206,7 +6382,7 @@
element, element,
() => { () => {
if (moveBefore) { if (moveBefore) {
@@ -793,7 +759,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
} else if (targetElement) { } else if (targetElement) {
targetElement.after(element); targetElement.after(element);
} else { } else {
@@ -6252,10 +6430,10 @@ @@ -6252,10 +6428,10 @@
* @param {TabMetricsContext} [metricsContext] * @param {TabMetricsContext} [metricsContext]
*/ */
moveTabToGroup(aTab, aGroup, metricsContext) { moveTabToGroup(aTab, aGroup, metricsContext) {
@@ -806,7 +772,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
return; return;
} }
if (aTab.group && aTab.group.id === aGroup.id) { if (aTab.group && aTab.group.id === aGroup.id) {
@@ -6285,6 +6463,7 @@ @@ -6285,6 +6461,7 @@
let state = { let state = {
tabIndex: tab._tPos, tabIndex: tab._tPos,
@@ -814,7 +780,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
}; };
if (tab.visible) { if (tab.visible) {
state.elementIndex = tab.elementIndex; state.elementIndex = tab.elementIndex;
@@ -6311,7 +6490,7 @@ @@ -6311,7 +6488,7 @@
let changedTabGroup = let changedTabGroup =
previousTabState.tabGroupId != currentTabState.tabGroupId; previousTabState.tabGroupId != currentTabState.tabGroupId;
@@ -823,7 +789,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
tab.dispatchEvent( tab.dispatchEvent(
new CustomEvent("TabMove", { new CustomEvent("TabMove", {
bubbles: true, bubbles: true,
@@ -6348,6 +6527,10 @@ @@ -6348,6 +6525,10 @@
moveActionCallback(); moveActionCallback();
@@ -834,7 +800,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
// Clear tabs cache after moving nodes because the order of tabs may have // Clear tabs cache after moving nodes because the order of tabs may have
// changed. // changed.
this.tabContainer._invalidateCachedTabs(); this.tabContainer._invalidateCachedTabs();
@@ -7249,7 +7432,7 @@ @@ -7249,7 +7430,7 @@
// preventDefault(). It will still raise the window if appropriate. // preventDefault(). It will still raise the window if appropriate.
break; break;
} }
@@ -843,7 +809,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
window.focus(); window.focus();
aEvent.preventDefault(); aEvent.preventDefault();
break; break;
@@ -7264,7 +7447,6 @@ @@ -7264,7 +7445,6 @@
} }
case "TabGroupCollapse": case "TabGroupCollapse":
aEvent.target.tabs.forEach(tab => { aEvent.target.tabs.forEach(tab => {
@@ -851,7 +817,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
}); });
break; break;
case "TabGroupCreateByUser": case "TabGroupCreateByUser":
@@ -8199,6 +8381,7 @@ @@ -8199,6 +8379,7 @@
aWebProgress.isTopLevel aWebProgress.isTopLevel
) { ) {
this.mTab.setAttribute("busy", "true"); this.mTab.setAttribute("busy", "true");
@@ -859,7 +825,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
gBrowser._tabAttrModified(this.mTab, ["busy"]); gBrowser._tabAttrModified(this.mTab, ["busy"]);
this.mTab._notselectedsinceload = !this.mTab.selected; this.mTab._notselectedsinceload = !this.mTab.selected;
} }
@@ -9200,7 +9383,7 @@ var TabContextMenu = { @@ -9200,7 +9381,7 @@ var TabContextMenu = {
); );
contextUnpinSelectedTabs.hidden = contextUnpinSelectedTabs.hidden =
!this.contextTab.pinned || !this.multiselected; !this.contextTab.pinned || !this.multiselected;
@@ -868,7 +834,7 @@ index 3204f253c23551650991d3385dd256d55892a012..792e54079e9f82013617306243fe313c
// Build Ask Chat items // Build Ask Chat items
TabContextMenu.GenAI.buildTabMenu( TabContextMenu.GenAI.buildTabMenu(
document.getElementById("context_askChat"), document.getElementById("context_askChat"),
@@ -9520,6 +9703,7 @@ var TabContextMenu = { @@ -9520,6 +9701,7 @@ var TabContextMenu = {
) )
); );
} else { } else {

View File

@@ -1495,6 +1495,7 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
continue; continue;
} }
tab.owner = null;
if (container) { if (container) {
if (tab.group?.hasAttribute('split-view-group')) { if (tab.group?.hasAttribute('split-view-group')) {
gBrowser.zenHandleTabMove(tab.group, () => { gBrowser.zenHandleTabMove(tab.group, () => {
@@ -2751,14 +2752,12 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
getTabsToExclude(aTab) { getTabsToExclude(aTab) {
const tabWorkspaceId = aTab.getAttribute('zen-workspace-id'); const tabWorkspaceId = aTab.getAttribute('zen-workspace-id');
const containerId = aTab.getAttribute('usercontextid') ?? '0';
// Return all tabs that are not on the same workspace // Return all tabs that are not on the same workspace
return this.allStoredTabs.filter( return this.allStoredTabs.filter(
(tab) => (tab) =>
tab.getAttribute('zen-workspace-id') !== tabWorkspaceId && tab.getAttribute('zen-workspace-id') !== tabWorkspaceId &&
!( !this._shouldShowTab(tab, tabWorkspaceId, containerId, this._workspaceCache) &&
this.containerSpecificEssentials &&
tab.getAttribute('container') !== aTab.getAttribute('container')
) &&
!tab.hasAttribute('zen-empty-tab') !tab.hasAttribute('zen-empty-tab')
); );
} }