Use more meaningful variable name
This commit is contained in:
parent
734b43333f
commit
2221ebe000
1 changed files with 9 additions and 8 deletions
|
@ -277,26 +277,27 @@ const backgroundLogic = {
|
||||||
const 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.
|
||||||
const afterIds = Array.from(sortMap.values()).reduce((acc, val) => acc.concat(val), []).map(tab => tab.id);
|
|
||||||
const beforeIds = sortedTabs.map(tab => tab.id);
|
const beforeIds = sortedTabs.map(tab => tab.id);
|
||||||
let sortedIds = beforeIds.slice(0);
|
const afterIds = Array.from(sortMap.values()).reduce((acc, val) => acc.concat(val), []).map(tab => tab.id);
|
||||||
|
let currentIds = beforeIds.slice(0);
|
||||||
for (const difference of differ.diff(beforeIds, afterIds)) {
|
for (const difference of differ.diff(beforeIds, afterIds)) {
|
||||||
if (!difference.added)
|
if (!difference.added)
|
||||||
continue;
|
continue;
|
||||||
const movingIds = difference.value;
|
const movingIds = difference.value;
|
||||||
const nearestFollowingIndex = afterIds.indexOf(movingIds[movingIds.length - 1]) + 1;
|
const lastMovingId = movingIds[movingIds.length - 1];
|
||||||
let newIndex = nearestFollowingIndex < afterIds.length ? sortedIds.indexOf(afterIds[nearestFollowingIndex]) : -1;
|
const nearestFollowingIndex = afterIds.indexOf(lastMovingId) + 1;
|
||||||
|
let newIndex = nearestFollowingIndex < afterIds.length ? currentIds.indexOf(afterIds[nearestFollowingIndex]) : -1;
|
||||||
if (newIndex < 0)
|
if (newIndex < 0)
|
||||||
newIndex = beforeIds.length;
|
newIndex = beforeIds.length;
|
||||||
const oldIndices = movingIds.map(id => sortedIds.indexOf(id));
|
const oldIndex = currentIds.indexOf(movingIds[0]);
|
||||||
if (oldIndices[0] < newIndex)
|
if (oldIndex < newIndex)
|
||||||
newIndex--;
|
newIndex--;
|
||||||
browser.tabs.move(movingIds, {
|
browser.tabs.move(movingIds, {
|
||||||
windowId: windowObj.id,
|
windowId: windowObj.id,
|
||||||
index: newIndex + offset
|
index: newIndex + offset
|
||||||
});
|
});
|
||||||
sortedIds = sortedIds.filter(id => !movingIds.includes(id));
|
currentIds = currentIds.filter(id => !movingIds.includes(id));
|
||||||
sortedIds.splice(newIndex, 0, ...movingIds);
|
currentIds.splice(newIndex, 0, ...movingIds);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue