From 82814b4c9a351e6b6f7cfb6d516d3c46a8b7a413 Mon Sep 17 00:00:00 2001 From: Jivan Flores Date: Thu, 12 Sep 2024 21:48:05 -0700 Subject: [PATCH 1/2] chore: Reformat ZenWorkspaces.mjs --- src/ZenWorkspaces.mjs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index b95a246..67424c2 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -102,7 +102,7 @@ var ZenWorkspaces = { // Convert all the icons to just the first character, just in case someone // decides to use a string with more than one character - _kIcons: JSON.parse(Services.prefs.getStringPref("zen.workspaces.icons")).map((icon) => icon[0]), + _kIcons: JSON.parse(Services.prefs.getStringPref('zen.workspaces.icons')).map((icon) => icon[0]), _initializeWorkspaceCreationIcons() { let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container'); @@ -243,8 +243,8 @@ var ZenWorkspaces = { (container) => container.userContextId === workspace.containerTabId ); if (containerGroup) { - element.classList.add("identity-color-" + containerGroup.color); - element.setAttribute("data-usercontextid", containerGroup.userContextId); + element.classList.add('identity-color-' + containerGroup.color); + element.setAttribute('data-usercontextid', containerGroup.userContextId); } let childs = window.MozXULElement.parseXULToFragment(`
@@ -605,9 +605,7 @@ var ZenWorkspaces = { async contextChangeContainerTab(event) { let workspaces = await this._workspaces(); let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId); - let userContextId = parseInt( - event.target.getAttribute("data-usercontextid") - ); + let userContextId = parseInt(event.target.getAttribute('data-usercontextid')); workspace.containerTabId = userContextId; await this.saveWorkspace(workspace); await this._propagateWorkspaceData(); @@ -684,7 +682,7 @@ var ZenWorkspaces = { // Tab browser utilities getContextIdIfNeeded(userContextId) { - if (typeof userContextId !== "undefined" || !this.workspaceEnabled) { + if (typeof userContextId !== 'undefined' || !this.workspaceEnabled) { return [userContextId, false]; } const activeWorkspace = this.getActiveWorkspaceFromCache(); From 569127a141613b09e68581a65aab4df6cb819f7e Mon Sep 17 00:00:00 2001 From: Jivan Flores Date: Fri, 13 Sep 2024 00:01:39 -0700 Subject: [PATCH 2/2] feat: Remember the last selected tab when cycling between workspaces --- src/ZenWorkspaces.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 67424c2..347a052 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -1,4 +1,9 @@ var ZenWorkspaces = { + /** + * Stores workspace IDs and their last selected tabs. + */ + _lastSelectedWorkspaceTabs: {}, + async init() { let docElement = document.documentElement; if ( @@ -166,6 +171,7 @@ var ZenWorkspaces = { console.info('ZenWorkspaces: Removing workspace', windowID); await this.changeWorkspace(json.workspaces.find((workspace) => workspace.uuid !== windowID)); this._deleteAllTabsInWorkspace(windowID); + delete this._lastSelectedWorkspaceTabs[windowID]; json.workspaces = json.workspaces.filter((workspace) => workspace.uuid !== windowID); await this.unsafeSaveWorkspaces(json); await this._propagateWorkspaceData(); @@ -497,7 +503,7 @@ var ZenWorkspaces = { } } if (firstTab) { - gBrowser.selectedTab = firstTab; + gBrowser.selectedTab = this._lastSelectedWorkspaceTabs[window.uuid] ?? firstTab; } if (typeof firstTab === 'undefined' && !onInit) { this._createNewTabForWorkspace(window); @@ -567,7 +573,9 @@ var ZenWorkspaces = { return; } tab.setAttribute('zen-workspace-id', activeWorkspace.uuid); + workspaceID = activeWorkspace.uuid; } + this._lastSelectedWorkspaceTabs[workspaceID] = tab; }, // Context menu management @@ -673,8 +681,14 @@ var ZenWorkspaces = { async changeTabWorkspace(workspaceID) { const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab]; + const previousWorkspaceID = document.documentElement.getAttribute('zen-workspace-id'); for (let tab of tabs) { tab.setAttribute('zen-workspace-id', 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]; + } } const workspaces = await this._workspaces(); await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));