Merge pull request #2753 from apostrophest/issue-2746-sort-ungrouped-tabs-only
Fix #2746: sort only ungrouped tabs
This commit is contained in:
@@ -343,7 +343,13 @@ const backgroundLogic = {
|
|||||||
let pos = 0;
|
let pos = 0;
|
||||||
|
|
||||||
// Let's collect UCIs/tabs for this window.
|
// Let's collect UCIs/tabs for this window.
|
||||||
|
/** @type {Map<string, {order: string, tabs: Tab[]}>} */
|
||||||
const map = new Map;
|
const map = new Map;
|
||||||
|
|
||||||
|
const lastTab = tabs.at(-1);
|
||||||
|
/** @type {boolean} */
|
||||||
|
let lastTabIsInTabGroup = !!lastTab && lastTab.groupId >= 0;
|
||||||
|
|
||||||
for (const tab of tabs) {
|
for (const tab of tabs) {
|
||||||
if (pinnedTabs && !tab.pinned) {
|
if (pinnedTabs && !tab.pinned) {
|
||||||
// We don't have, or we already handled all the pinned tabs.
|
// We don't have, or we already handled all the pinned tabs.
|
||||||
@@ -356,6 +362,11 @@ const backgroundLogic = {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tab.groupId >= 0) {
|
||||||
|
// Skip over tabs in tab groups until it's possible to handle them better.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!map.has(tab.cookieStoreId)) {
|
if (!map.has(tab.cookieStoreId)) {
|
||||||
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId);
|
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId);
|
||||||
map.set(tab.cookieStoreId, { order: userContextId, tabs: [] });
|
map.set(tab.cookieStoreId, { order: userContextId, tabs: [] });
|
||||||
@@ -377,15 +388,25 @@ const backgroundLogic = {
|
|||||||
const sortMap = new Map([...map.entries()].sort((a, b) => a[1].order > b[1].order));
|
const sortMap = new Map([...map.entries()].sort((a, b) => a[1].order > b[1].order));
|
||||||
|
|
||||||
// Let's move tabs.
|
// Let's move tabs.
|
||||||
sortMap.forEach(obj => {
|
for (const { tabs } of sortMap.values()) {
|
||||||
for (const tab of obj.tabs) {
|
for (const tab of tabs) {
|
||||||
++pos;
|
++pos;
|
||||||
browser.tabs.move(tab.id, {
|
browser.tabs.move(tab.id, {
|
||||||
windowId: windowObj.id,
|
windowId: windowObj.id,
|
||||||
index: pos
|
index: pinnedTabs ? pos : -1
|
||||||
});
|
});
|
||||||
|
// Pinned tabs are never grouped and always inserted in the front.
|
||||||
|
if (!pinnedTabs && lastTabIsInTabGroup && browser.tabs.ungroup) {
|
||||||
|
// If the last item in the tab strip is a grouped tab, moving a tab
|
||||||
|
// to its position will also add it to the tab group. Since this code
|
||||||
|
// is only sorting ungrouped tabs, this forcibly ungroups the first
|
||||||
|
// tab to be moved. All subsequent iterations will only be moving
|
||||||
|
// ungrouped tabs to the position of other ungrouped tabs.
|
||||||
|
lastTabIsInTabGroup = false;
|
||||||
|
browser.tabs.ungroup(tab.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async hideTabs(options) {
|
async hideTabs(options) {
|
||||||
|
|||||||
Reference in New Issue
Block a user