diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 2f28dee..851730d 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -56,6 +56,7 @@ var ZenWorkspaces = { await IOUtils.writeJSON(this._storeFile, {}); } if (this.workspaceEnabled) { + window.addEventListener("TabClose", this.handleTabClose.bind(this)); let workspaces = await this._workspaces(); if (workspaces.workspaces.length === 0) { await this.createAndSaveWorkspace("Default Workspace", true); @@ -80,6 +81,20 @@ var ZenWorkspaces = { } }, + handleTabClose(event) { + let tab = event.target; + let workspaceID = tab.getAttribute("zen-workspace-id"); + // If the tab is the last one in the workspace, create a new tab + if (workspaceID) { + let tabs = gBrowser.tabs.filter(tab => tab.getAttribute("zen-workspace-id") === workspaceID); + if (tabs.length === 1) { + this._createNewTabForWorkspace({ uuid: workspaceID }); + // We still need to close other tabs in the workspace + this.changeWorkspace({ uuid: workspaceID }); + } + } + }, + _initializeWorkspaceIcons() { const kIcons = ["🏠", "📄", "💹", "💼", "📧", "✅", "👥"]; let container = document.getElementById("PanelUI-zen-workspaces-create-icons-container");