Fixed common issues with workspaces and the new empty tab

This commit is contained in:
mr. m
2025-02-20 11:53:33 +01:00
parent 61311bd3e6
commit c1870fee32
6 changed files with 77 additions and 25 deletions

View File

@@ -631,6 +631,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
* @param {string} gridType - The type of grid layout.
*/
splitTabs(tabs, gridType) {
tabs = tabs.filter((tab) => !tab.hasAttribute("zen-empty-tab"));
if (tabs.length < 2) {
return;
}

View File

@@ -50,10 +50,12 @@
}
function openWelcomeTab() {
const currentSelectedTab = window.gBrowser.selectedTab;
const tab = window.gBrowser.addTrustedTab('https://zen-browser.app/welcome', {
inBackground: true,
});
gBrowser.selectedTab = tab;
gBrowser.removeTab(currentSelectedTab);
}
class ZenWelcomePages {
@@ -425,6 +427,8 @@
});
gZenPinnedTabManager.addToEssentials(createdTab);
}
openInitialPinTab();
openWelcomeTab();
},
},
{
@@ -513,8 +517,6 @@
centerWindowOnScreen();
initializeZenWelcome();
animateInitialStage();
openInitialPinTab();
openWelcomeTab();
}
startZenWelcome();

View File

@@ -115,19 +115,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
selectEmptyTab() {
if (this._emptyTab) {
if (!Services.prefs.getBoolPref('zen.urlbar.replace-newtab')) {
if (this._emptyTab && Services.prefs.getBoolPref('zen.urlbar.replace-newtab')) {
gBrowser.selectedTab = this._emptyTab;
return this._emptyTab;
}
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
if (window.uuid) {
tab.setAttribute('zen-workspace-id', this.activeWorkspace);
}
return tab;
}
gBrowser.selectedTab = this._emptyTab;
return this._emptyTab;
}
return null;
}
async delayedStartup() {
if (!this.workspaceEnabled) {
@@ -176,15 +173,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
get tabboxChildren() {
const childs = Array.from(this.tabboxChildrenWithoutEmpty);
if (this._emptyTab) {
childs.unshift(this._emptyTab);
}
return childs;
return Array.from(this.activeWorkspaceStrip?.children || []);
}
get tabboxChildrenWithoutEmpty() {
return this.activeWorkspaceStrip?.children || [];
return this.tabboxChildren.filter((child) => !child.hasAttribute('zen-empty-tab'));
}
get pinnedTabsContainer() {
@@ -1494,11 +1487,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
// First pass: Handle tab visibility and workspace ID assignment
this._processTabVisibility(window.uuid, containerId, workspaces);
const prevTabUsed = this._processTabVisibility(window.uuid, containerId, workspaces);
// Second pass: Handle tab selection
this.tabContainer._invalidateCachedTabs();
const tabToSelect = await this._handleTabSelection(window, onInit, containerId, workspaces, previousWorkspace.uuid);
const tabToSelect = await this._handleTabSelection(window, onInit, containerId, workspaces, previousWorkspace.uuid, prevTabUsed);
// Update UI and state
await this._updateWorkspaceState(window, onInit, tabToSelect);
@@ -1616,16 +1609,19 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// If there's no more visible tabs, make a new tab visible
// or if ALL the visible tabs are essentials or we have our selected
// tab hidden, select a new tab
let prevTabUsed = null;
if (
hiddenTabs.length === visibleTabs.length ||
visibleTabs.every((tab) => tab.getAttribute('zen-essential') === 'true') ||
hiddenTabs.includes(gBrowser.selectedTab)
) {
prevTabUsed = gBrowser.selectedTab;
this.selectEmptyTab();
}
for (const tab of hiddenTabs) {
gBrowser.hideTab(tab, undefined, true);
}
return prevTabUsed;
}
_shouldShowTab(tab, workspaceUuid, containerId, workspaces) {
@@ -1664,8 +1660,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return tabWorkspaceId === workspaceUuid;
}
async _handleTabSelection(window, onInit, containerId, workspaces, previousWorkspaceId) {
const currentSelectedTab = gBrowser.selectedTab;
async _handleTabSelection(window, onInit, containerId, workspaces, previousWorkspaceId, prevTabUsed) {
const currentSelectedTab = prevTabUsed || gBrowser.selectedTab;
const oldWorkspaceId = previousWorkspaceId;
const lastSelectedTab = this._lastSelectedWorkspaceTabs[window.uuid];
@@ -1739,6 +1735,14 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Update workspace indicator
await this.updateWorkspaceIndicator(window, this.workspaceIndicator);
// Fix ctrl+tab behavior. Note, we dont call it with "await" because we dont want to wait for it
this._fixCtrlTabBehavior();
}
async _fixCtrlTabBehavior() {
ctrlTab.uninit();
ctrlTab.readPref();
}
_invalidateBookmarkContainers() {
@@ -1912,6 +1916,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const contaienr = document.querySelector(
`#vertical-pinned-tabs-container .zen-workspace-tabs-section[zen-workspace-id="${workspaceId}"]`
);
console.log(tab)
contaienr.insertBefore(tab, contaienr.firstChild);
changed = true;
}
@@ -1981,6 +1986,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._contextMenuId = null;
}
findTabToBlur(tab) {
return (tab.hasAttribute('zen-essential') && this._emptyTab) ? this._emptyTab : tab;
}
async setDefaultWorkspace() {
await ZenWorkspacesStorage.setDefaultWorkspace(this._contextMenuId);
await this._propagateWorkspaceData();
@@ -2157,7 +2166,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Session restore functions
get allStoredTabs() {
if (!this._hasInitializedTabsStrip) {
const children = Array.from(this.tabboxChildren);
const children = this.tabboxChildren;
children.pop(); // Remove the last child which is the new tab button
return children;
}

View File

@@ -0,0 +1,13 @@
diff --git a/browser/components/tabbrowser/content/browser-ctrlTab.js b/browser/components/tabbrowser/content/browser-ctrlTab.js
index e5d16e605b7edf11fc9f52b93e415087b76398f1..feb7ccfc0562efda56177a75454a9f83a332e8d1 100644
--- a/browser/components/tabbrowser/content/browser-ctrlTab.js
+++ b/browser/components/tabbrowser/content/browser-ctrlTab.js
@@ -761,7 +761,7 @@ var ctrlTab = {
_initRecentlyUsedTabs() {
this._recentlyUsedTabs = Array.prototype.filter.call(
gBrowser.tabs,
- tab => !tab.closing && !tab.hidden
+ tab => !tab.closing && !tab.hidden && !tab.hasAttribute("zen-empty-tab")
);
this._sortRecentlyUsedTabs();
},

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cb4a77fa5992b9890dfc55cb3c3c558d07912bb1 100644
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..5ae4351d7438c0e03c0a24551c910d43a2c676bd 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -406,11 +406,52 @@
@@ -365,6 +365,24 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cb4a77fa5992b9890dfc55cb3c3c558d
if (!this._windowIsClosing) {
if (wasPinned) {
this.tabContainer._positionPinnedTabs();
@@ -5025,7 +5132,7 @@
!excludeTabs.has(aTab.owner) &&
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
) {
- return aTab.owner;
+ return ZenWorkspaces.findTabToBlur(aTab.owner);
}
// Try to find a remaining tab that comes after the given tab
@@ -5047,7 +5154,7 @@
}
if (tab) {
- return tab;
+ return ZenWorkspaces.findTabToBlur(tab);
}
// If no qualifying visible tab was found, see if there is a tab in
@@ -5465,10 +5572,10 @@
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
}

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js
index 8aeb244ffca9f48661805f5b7d860b5896055562..b2e3b6c9c37eb1a070bbea72d629f9f72676f5bf 100644
index 8aeb244ffca9f48661805f5b7d860b5896055562..c96e563a31b4c32c855cc2d250d702361b427f88 100644
--- a/browser/components/tabbrowser/content/tabs.js
+++ b/browser/components/tabbrowser/content/tabs.js
@@ -94,7 +94,7 @@
@@ -151,6 +151,15 @@ index 8aeb244ffca9f48661805f5b7d860b5896055562..b2e3b6c9c37eb1a070bbea72d629f9f7
return children.filter(node => node.tagName == "tab-group");
}
@@ -1540,7 +1568,7 @@
*/
get visibleTabs() {
if (!this.#visibleTabs) {
- this.#visibleTabs = this.openTabs.filter(tab => tab.visible);
+ this.#visibleTabs = this.openTabs.filter(tab => tab.visible && !tab.hasAttribute("zen-empty-tab"));
}
return this.#visibleTabs;
}
@@ -1574,10 +1602,8 @@
return this.#focusableItems;
}
@@ -160,7 +169,7 @@ index 8aeb244ffca9f48661805f5b7d860b5896055562..b2e3b6c9c37eb1a070bbea72d629f9f7
- );
- let children = Array.from(this.arrowScrollbox.children);
+ let verticalPinnedTabsContainer = this.verticalPinnedTabsContainer;
+ let children = Array.from(ZenWorkspaces.tabboxChildrenWithoutEmpty);
+ let children = ZenWorkspaces.tabboxChildrenWithoutEmpty;
let focusableItems = [];
for (let child of children) {