chore: Better support for restoring previous tabs, b=(no-bug), c=workspaces

This commit is contained in:
Mr. M 2025-05-10 20:00:25 +02:00
parent cc1619ab5d
commit 1f68a45417
No known key found for this signature in database
GPG key ID: 6292C4C8F8652B18
2 changed files with 48 additions and 29 deletions

View file

@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index 6dece2b9d0462d90a28e75350ce983d87816ef73..1d179c969f2fc29f8664ddae4a1536a9b95e7327 100644
index 6dece2b9d0462d90a28e75350ce983d87816ef73..a2fd09d94746bbb8ba16c5e234c6e99c2eb25c4c 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -415,11 +415,45 @@
@ -383,7 +383,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..1d179c969f2fc29f8664ddae4a1536a9
if (typeof index != "number") {
// Move the new tab after another tab if needed, to the end otherwise.
- index = Infinity;
+ index = Services.prefs.getBoolPref("zen.view.show-newtab-button-top") ? this.pinnedTabCount : Infinity;
+ index = Services.prefs.getBoolPref("zen.view.show-newtab-button-top") ? this._numVisiblePinTabsWithoutCollapsed : Infinity;
if (
!bulkOrderedOpen &&
((openerTab &&
@ -403,9 +403,10 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..1d179c969f2fc29f8664ddae4a1536a9
- index = Math.max(index, 0);
- index = Math.min(index, this.pinnedTabCount);
+ index = Math.max(index, tab.hasAttribute("zen-essential") ? 0 : this._numZenEssentials);
+ index = Math.min(index, tab.hasAttribute("zen-essential") ? this._numZenEssentials : this.pinnedTabCount);
+ index = Math.min(index, tab.hasAttribute("zen-essential") ? this._numZenEssentials : this._numVisiblePinTabsWithoutCollapsed);
} else {
index = Math.max(index, this.pinnedTabCount);
- index = Math.max(index, this.pinnedTabCount);
+ index = Math.max(index, this._numVisiblePinTabsWithoutCollapsed);
index = Math.min(index, this.tabContainer.ariaFocusableItems.length);
}

View file

@ -799,37 +799,33 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return;
}
let showed = false;
let resolveSelectPromise;
let selectPromise = new Promise((resolve) => {
resolveSelectPromise = resolve;
});
const cleanup = () => {
if (this._initialTab?._veryPossiblyEmpty && !this._initialTab?.selected) {
gBrowser.removeTab(this._initialTab, {
skipSessionStore: true,
animate: false,
});
}
delete this._tabToSelect;
delete this._tabToRemoveForEmpty;
resolveSelectPromise();
};
if (this._initialTab) {
if (this._initialTab._shouldRemove && this._initialTab._veryPossiblyEmpty) {
this._removedByStartupPage = true;
gBrowser.removeTab(this._initialTab, {
skipSessionStore: true,
});
} else {
this.moveTabToWorkspace(this._initialTab, this.activeWorkspace);
gBrowser.selectedTab = this._initialTab;
gBrowser.moveTabTo(this._initialTab, { forceUngrouped: true, tabIndex: 0 });
}
let removedEmptyTab = false;
if (this._initialTab && !(this._initialTab._shouldRemove && this._initialTab._veryPossiblyEmpty)) {
gBrowser.selectedTab = this._initialTab;
this.moveTabToWorkspace(this._initialTab, this.activeWorkspace);
gBrowser.moveTabTo(this._initialTab, { forceUngrouped: true, tabIndex: 0 });
removedEmptyTab = true;
delete this._initialTab;
}
if (this._tabToRemoveForEmpty) {
if (this._tabToRemoveForEmpty && !removedEmptyTab) {
const tabs = gBrowser.tabs.filter((tab) => !tab.collapsed && !tab.hasAttribute('zen-empty-tab'));
if (
typeof this._tabToSelect === 'number' &&
this._tabToSelect >= 0 &&
tabs[this._tabToSelect] &&
this._shouldShowTab(tabs[this._tabToSelect]) &&
(await this.#shouldShowTabInCurrentWorkspace(tabs[this._tabToSelect])) &&
tabs[this._tabToSelect] !== this._tabToRemoveForEmpty
) {
setTimeout(() => {
@ -844,15 +840,29 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} else {
this.selectEmptyTab();
showed = true;
this._removedByStartupPage = true;
gBrowser.removeTab(this._tabToRemoveForEmpty, {
skipSessionStore: true,
});
cleanup();
setTimeout(() => {
this._removedByStartupPage = true;
gBrowser.removeTab(this._tabToRemoveForEmpty, {
skipSessionStore: true,
});
cleanup();
}, 0);
}
} else {
cleanup();
setTimeout(() => {
cleanup();
}, 0);
}
await selectPromise;
if (this._initialTab) {
this._removedByStartupPage = true;
gBrowser.removeTab(this._initialTab, {
skipSessionStore: true,
});
delete this._initialTab;
}
if (gZenVerticalTabsManager._canReplaceNewTab && showed) {
BrowserCommands.openTab();
}
@ -897,6 +907,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
!workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID)
) {
// Remove any tabs where their workspace doesn't exist anymore
gBrowser.unpinTab(tab);
gBrowser.removeTab(tab, {
skipSessionStore: true,
closeWindowWithLastTab: false,
@ -2259,6 +2270,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return !(aTab?.hasAttribute('zen-essential') || (aTab?.pinned && aTab?.hasAttribute('pending')));
}
async #shouldShowTabInCurrentWorkspace(tab) {
const currentWorkspace = this.getActiveWorkspaceFromCache();
return this._shouldShowTab(tab, currentWorkspace.uuid, currentWorkspace.containerTabId, await this._workspaces());
}
_shouldShowTab(tab, workspaceUuid, containerId, workspaces) {
const isEssential = tab.getAttribute('zen-essential') === 'true';
const tabWorkspaceId = tab.getAttribute('zen-workspace-id');
@ -2398,6 +2414,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}
}
setTimeout(gURLBar.formatValue.bind(gURLBar), 0);
}
async _fixCtrlTabBehavior() {