look up order in a map
This commit is contained in:
@@ -73,13 +73,12 @@ module.exports = class RibbonClasp extends Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
// anything we haven't seen before sorts to the bottom, in the order it came in
|
||||
const rank = new Map(order.map((id, i) => [id, i]));
|
||||
const sorted = [...ribbon.items].sort((a, b) => {
|
||||
const ia = order.indexOf(a.id);
|
||||
const ib = order.indexOf(b.id);
|
||||
if (ia === -1 && ib === -1) return 0;
|
||||
if (ia === -1) return 1;
|
||||
if (ib === -1) return -1;
|
||||
return ia - ib;
|
||||
const ia = rank.get(a.id) ?? Infinity;
|
||||
const ib = rank.get(b.id) ?? Infinity;
|
||||
return ia === ib ? 0 : ia - ib;
|
||||
});
|
||||
|
||||
const changed = sorted.some((item, i) => ribbon.items[i] !== item);
|
||||
|
||||
Reference in New Issue
Block a user