Refactor tab selection logic in ZenWorkspaces to improve clarity and maintainability

This commit is contained in:
mr. M
2025-02-21 23:09:30 +01:00
parent 079ec27a21
commit 32ab4a660f

View File

@@ -1689,6 +1689,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return tabWorkspaceId === workspaceUuid; return tabWorkspaceId === workspaceUuid;
} }
_shouldChangeToTab(aTab) {
return !(aTab.hasAttribute('zen-essential') || (aTab.pinned && aTab.hasAttribute('pending')));
}
async _handleTabSelection(window, onInit, containerId, workspaces, previousWorkspaceId, prevTabUsed) { async _handleTabSelection(window, onInit, containerId, workspaces, previousWorkspaceId, prevTabUsed) {
const currentSelectedTab = prevTabUsed || gBrowser.selectedTab; const currentSelectedTab = prevTabUsed || gBrowser.selectedTab;
const oldWorkspaceId = previousWorkspaceId; const oldWorkspaceId = previousWorkspaceId;
@@ -1710,7 +1714,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
if (!tabToSelect && gBrowser.visibleTabs.length) { if (!tabToSelect && gBrowser.visibleTabs.length) {
tabToSelect = gBrowser.visibleTabs[gBrowser.visibleTabs.length - 1]; tabToSelect = gBrowser.visibleTabs[gBrowser.visibleTabs.length - 1];
} }
if (tabToSelect?.hasAttribute('zen-essential') || (tabToSelect?.pinned && tabToSelect?.hasAttribute('pending'))) { if (!tabToSelect || !this._shouldChangeToTab(tabToSelect)) {
// Never select an essential tab // Never select an essential tab
tabToSelect = null; tabToSelect = null;
} }
@@ -2021,7 +2025,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
findTabToBlur(tab) { findTabToBlur(tab) {
return tab.hasAttribute('zen-essential') && this._emptyTab ? this._emptyTab : tab; return !this._shouldChangeToTab(tab) && this._emptyTab ? this._emptyTab : tab;
} }
async setDefaultWorkspace() { async setDefaultWorkspace() {