From 76fc91be9a539df6223e9a8a3e835d180620347f Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 17 Feb 2017 10:04:54 +0100 Subject: [PATCH] Remap tabs when open/close/activated #179 --- index.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index de6bd71..142dce8 100644 --- a/index.js +++ b/index.js @@ -129,25 +129,20 @@ const ContainerService = { } tabs.on("open", tab => { - const userContextId = this._getUserContextIdFromTab(tab); - if (userContextId) { - ++this._identitiesState[userContextId].openTabs; - } this._hideAllPanels(); this._restyleTab(tab); + this._remapTab(tab); }); tabs.on("close", tab => { - const userContextId = this._getUserContextIdFromTab(tab); - if (userContextId && this._identitiesState[userContextId].openTabs) { - --this._identitiesState[userContextId].openTabs; - } this._hideAllPanels(); + this._remapTab(tab); }); tabs.on("activate", tab => { this._hideAllPanels(); this._restyleActiveTab(tab).catch(() => {}); + this._remapTab(tab); }); // Modify CSS and other stuff for each window. @@ -318,11 +313,23 @@ const ContainerService = { } this._identitiesState[userContextId] = this._createIdentityState(); + this._remapTabsFromUserContextId(userContextId); + }, + + _remapTabsFromUserContextId(userContextId) { + this._identitiesState[userContextId].openTabs = 0; this._containerTabIterator(userContextId, () => { ++this._identitiesState[userContextId].openTabs; }); }, + _remapTab(tab) { + const userContextId = this._getUserContextIdFromTab(tab); + if (userContextId) { + this._remapTabsFromUserContextId(userContextId); + } + }, + _isKnownContainer(userContextId) { return userContextId in this._identitiesState; },