From 9c93a214210c94dbd73eb9e38bd2430919284dec Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Fri, 25 Apr 2025 15:33:49 +0200 Subject: [PATCH] fix: Fixed workspaces not switching when they need to if the target tab is an essential, b=(no-bug), c=workspaces --- src/zen/workspaces/ZenWorkspaces.mjs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index ef4e9bad1..535e6a0ba 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -2778,7 +2778,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { // Check if we need to change workspace if ( tab.getAttribute('zen-workspace-id') !== this.activeWorkspace || - (currentWorkspace.containerTabId !== tab.getAttribute('usercontextid') && this.containerSpecificEssentials) + tab.hasAttribute('zen-essential') || + (currentWorkspace.containerTabId !== parseInt(tab.parentNode.getAttribute('container')) && + this.containerSpecificEssentials) ) { // Use a mutex-like approach to prevent concurrent workspace changes if (this._workspaceChangeInProgress) { @@ -2786,12 +2788,22 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { return; } + let workspaceToSwitch = undefined; + if (tab.hasAttribute('zen-essential')) { + // Find first workspace with the same container + const containerTabId = parseInt(tab.parentNode.getAttribute('container')); + workspaceToSwitch = this._workspaceCache.workspaces.find((workspace) => workspace.containerTabId === containerTabId); + } else { + workspaceToSwitch = this._workspaceCache.workspaces.find((workspace) => workspace.uuid === tab.getAttribute('zen-workspace-id')); + } + if (!workspaceToSwitch) { + console.error('No workspace found for tab, cannot switch'); + return; + } + this._workspaceChangeInProgress = true; try { - await this.changeWorkspace({ - uuid: tab.getAttribute('zen-workspace-id'), - containerTabId: tab.getAttribute('usercontextid'), - }); + await this.changeWorkspace(workspaceToSwitch); } finally { this._workspaceChangeInProgress = false; }