Issue #74: pinned tabs sorted

This commit is contained in:
baku 2017-01-11 06:52:14 +00:00
parent a6bfaabb9c
commit bc7556d028

View file

@ -177,19 +177,22 @@ let ContainerService = {
}, },
sortTabs() { sortTabs() {
return new Promise(resolve => { function sortTabsInternal(window, pinnedTabs) {
for (let window of windows.browserWindows) {
// From model to XUL window. // From model to XUL window.
window = viewFor(window); const xulWindow = viewFor(window);
let tabs = tabsUtils.getTabs(window);
const tabs = tabsUtils.getTabs(xulWindow);
let pos = 0; let pos = 0;
// Let"s collect UCIs/tabs for this window. // Let's collect UCIs/tabs for this window.
let map = new Map; let map = new Map;
for (let tab of tabs) { for (const tab of tabs) {
if (tabsUtils.isPinned(tab)) { if (pinnedTabs && !tabsUtils.isPinned(tab)) {
// We don't have, or we already handled all the pinned tabs.
break;
}
if (!pinnedTabs && tabsUtils.isPinned(tab)) {
// pinned tabs must be consider as taken positions. // pinned tabs must be consider as taken positions.
++pos; ++pos;
continue; continue;
@ -202,17 +205,23 @@ let ContainerService = {
map.get(userContextId).push(tab); map.get(userContextId).push(tab);
} }
// Let"s sort the map. // Let's sort the map.
let sortMap = new Map([...map.entries()].sort((a, b) => a[0] > b[0])); const sortMap = new Map([...map.entries()].sort((a, b) => a[0] > b[0]));
// Let"s move tabs. // Let's move tabs.
sortMap.forEach(tabs => { sortMap.forEach(tabs => {
for (let tab of tabs) { for (const tab of tabs) {
window.gBrowser.moveTabTo(tab, pos++); xulWindow.gBrowser.moveTabTo(tab, pos++);
} }
}); });
} }
return new Promise(resolve => {
for (let window of windows.browserWindows) {
// First the pinned tabs, then the normal ones.
sortTabsInternal(window, true);
sortTabsInternal(window, false);
}
resolve(null); resolve(null);
}); });
}, },