diff --git a/src/zen/spaces/ZenSpaceManager.mjs b/src/zen/spaces/ZenSpaceManager.mjs index 0c7c6b19f..78d990899 100644 --- a/src/zen/spaces/ZenSpaceManager.mjs +++ b/src/zen/spaces/ZenSpaceManager.mjs @@ -1589,6 +1589,11 @@ class nsZenWorkspaces { } moveTabsToWorkspace(tabs, workspaceID) { + const newTabPlacement = Services.prefs.getBoolPref( + "zen.view.show-newtab-button-top", + false + ); + tabs = newTabPlacement ? tabs.reverse() : tabs; for (let tab of tabs) { const workspaceContainer = this.workspaceElement(workspaceID); const container = tab.pinned @@ -1603,14 +1608,11 @@ class nsZenWorkspaces { } if (container) { - const newtabPlacement = Services.prefs.getBoolPref( - "zen.view.show-newtab-button-top", - false - ); - const insertElement = newtabPlacement + const insertElement = newTabPlacement ? container.firstChild : container.lastChild; + const previousWorkspaceID = tab.getAttribute("zen-workspace-id"); if (tab.group?.hasAttribute("split-view-group")) { gBrowser.zenHandleTabMove(tab.group, () => { for (const subTab of tab.group.tabs) { @@ -1624,6 +1626,12 @@ class nsZenWorkspaces { tab.setAttribute("zen-workspace-id", workspaceID); container.insertBefore(tab, insertElement); }); + + if (this.lastSelectedWorkspaceTabs[previousWorkspaceID] === tab) { + // This tab is no longer the last selected tab in the previous workspace because it's being moved to + // the current workspace + delete this.lastSelectedWorkspaceTabs[previousWorkspaceID]; + } } // also change glance tab if it's the same tab const glanceTab = tab.querySelector(".tabbrowser-tab[zen-glance-tab]"); @@ -1696,6 +1704,7 @@ class nsZenWorkspaces { try { this.log("Changing workspace to", workspace?.uuid); await this.#performWorkspaceChange(workspace, ...args); + this.updateWorkspacesChangeContextMenu(); } catch (e) { console.error("gZenWorkspaces: Error changing workspace", e); } @@ -2473,7 +2482,9 @@ class nsZenWorkspaces { if (gZenWorkspaces.privateWindowOrDisabled) { return; } - const workspaces = this.getWorkspaces(); + const workspaces = this.getWorkspaces().filter( + w => w.uuid !== this.activeWorkspace + ); const ctxCommand = document.getElementById("cmd_zenCtxDeleteWorkspace"); if (workspaces.length <= 1) { ctxCommand.setAttribute("disabled", "true"); @@ -2936,15 +2947,7 @@ class nsZenWorkspaces { ? gBrowser.selectedTabs : [TabContextMenu.contextTab]; document.getElementById("tabContextMenu").hidePopup(); - for (let tab of tabs) { - const previousWorkspaceID = tab.getAttribute("zen-workspace-id"); - this.moveTabToWorkspace(tab, workspaceID); - if (this.lastSelectedWorkspaceTabs[previousWorkspaceID] === tab) { - // This tab is no longer the last selected tab in the previous workspace because it's being moved to - // the current workspace - delete this.lastSelectedWorkspaceTabs[previousWorkspaceID]; - } - } + this.moveTabsToWorkspace(tabs, workspaceID); // Make sure we select the last tab in the new workspace this.lastSelectedWorkspaceTabs[workspaceID] = gZenGlanceManager.getTabOrGlanceParent(tabs[tabs.length - 1]);