Refactor tab selection and new tab handling logic in ZenWorkspaces for improved clarity and maintainability

This commit is contained in:
mr. M
2025-02-22 00:02:12 +01:00
parent 5e256b9beb
commit 8e64623592
3 changed files with 19 additions and 8 deletions

View File

@@ -165,8 +165,7 @@ var gZenUIManager = {
_lastTab: null, _lastTab: null,
handleNewTab(werePassedURL, searchClipboard, where) { handleNewTab(werePassedURL, searchClipboard, where) {
const shouldOpenURLBar = const shouldOpenURLBar = gZenVerticalTabsManager._canReplaceNewTab && !werePassedURL && !searchClipboard && where === 'tab';
Services.prefs.getBoolPref('zen.urlbar.replace-newtab') && !werePassedURL && !searchClipboard && where === 'tab';
if (shouldOpenURLBar) { if (shouldOpenURLBar) {
if (this._clearTimeout) { if (this._clearTimeout) {
clearTimeout(this._clearTimeout); clearTimeout(this._clearTimeout);
@@ -279,6 +278,7 @@ var gZenVerticalTabsManager = {
); );
}); });
XPCOMUtils.defineLazyPreferenceGetter(this, '_canReplaceNewTab', 'zen.urlbar.replace-newtab', true);
var updateEvent = this._updateEvent.bind(this); var updateEvent = this._updateEvent.bind(this);
var onPrefChange = this._onPrefChange.bind(this); var onPrefChange = this._onPrefChange.bind(this);

View File

@@ -561,6 +561,7 @@
state.index = 0; state.index = 0;
SessionStore.setTabState(tab, state); SessionStore.setTabState(tab, state);
this.resetPinChangedUrl(tab);
} }
async getFaviconAsBase64(pageUrl) { async getFaviconAsBase64(pageUrl) {

View File

@@ -107,7 +107,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
selectEmptyTab() { selectEmptyTab() {
if (this._emptyTab && Services.prefs.getBoolPref('zen.urlbar.replace-newtab')) { if (this._emptyTab && gZenVerticalTabsManager._canReplaceNewTab) {
gBrowser.selectedTab = this._emptyTab; gBrowser.selectedTab = this._emptyTab;
return this._emptyTab; return this._emptyTab;
} }
@@ -608,7 +608,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
showed = true; showed = true;
} }
} }
if (Services.prefs.getBoolPref('zen.urlbar.replace-newtab') && showed) { if (gZenVerticalTabsManager._canReplaceNewTab && showed) {
BrowserCommands.openTab(); BrowserCommands.openTab();
} }
} }
@@ -1640,9 +1640,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// tab hidden, select a new tab // tab hidden, select a new tab
let prevTabUsed = null; let prevTabUsed = null;
if ( if (
hiddenTabs.length === visibleTabs.length || (hiddenTabs.length === visibleTabs.length ||
visibleTabs.every((tab) => tab.getAttribute('zen-essential') === 'true') || visibleTabs.every((tab) => tab.getAttribute('zen-essential') === 'true') ||
hiddenTabs.includes(gBrowser.selectedTab) hiddenTabs.includes(gBrowser.selectedTab)) &&
gZenVerticalTabsManager._canReplaceNewTab
) { ) {
prevTabUsed = gBrowser.selectedTab; prevTabUsed = gBrowser.selectedTab;
this.selectEmptyTab(); this.selectEmptyTab();
@@ -1733,6 +1734,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Always make sure we always unselect the tab from the old workspace // Always make sure we always unselect the tab from the old workspace
if (currentSelectedTab && currentSelectedTab !== tabToSelect) { if (currentSelectedTab && currentSelectedTab !== tabToSelect) {
currentSelectedTab._selected = false; currentSelectedTab._selected = false;
if (
!this._shouldShowTab(currentSelectedTab, window.uuid, containerId, workspaces) &&
currentSelectedTab.hasAttribute('zen-essential')
) {
gBrowser.hideTab(currentSelectedTab, undefined, true);
}
} }
return tabToSelect; return tabToSelect;
} }
@@ -2025,7 +2032,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
findTabToBlur(tab) { findTabToBlur(tab) {
return !this._shouldChangeToTab(tab) && this._emptyTab ? this._emptyTab : tab; if (!this._shouldChangeToTab(tab) && this._emptyTab) {
return this._emptyTab;
}
return tab;
} }
async setDefaultWorkspace() { async setDefaultWorkspace() {