From 4b92b775b4f3275dbd03468a7c4367def63eef14 Mon Sep 17 00:00:00 2001 From: baku Date: Sat, 7 Jan 2017 09:24:17 +0100 Subject: [PATCH] Sorting must work with pinned tabs as well --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 44d5da9..59de8c7 100644 --- a/index.js +++ b/index.js @@ -124,22 +124,27 @@ let ContainerService = for (let window of windows) { let tabs = tabsUtils.getTabs(window); - // Let's collect UCIs for each tab of this window. + let pos = 0; + + // Let's collect UCIs/tabs for this window. let map = new Map; for (let tab of tabs) { - let xulTab = viewFor(tab); - let userContextId = parseInt(xulTab.getAttribute('usercontextid') || 0, 10); + if (tabsUtils.isPinned(tab)) { + // pinned tabs must be consider as taken positions. + ++pos; + continue; + } + + let userContextId = parseInt(tab.getAttribute('usercontextid') || 0, 10); if (!map.has(userContextId)) { map.set(userContextId, []); } - map.get(userContextId).push(xulTab); + map.get(userContextId).push(tab); } // Let's sort the map. let sortMap = new Map([...map.entries()].sort((a, b) => a[0] > b[0])); - let pos = 0; - // Let's move tabs. for (let [userContextId, tabs] of sortMap) { for (let tab of tabs) {