mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 15:05:26 +02:00
rewrite to splices
This commit is contained in:
parent
d9dc2bf96b
commit
4299123855
1 changed files with 3 additions and 11 deletions
|
@ -88,18 +88,10 @@ class PagesOrder {
|
||||||
const children = await Model.get(parentPageId);
|
const children = await Model.get(parentPageId);
|
||||||
const found1 = children.order.indexOf(putAbovePageId);
|
const found1 = children.order.indexOf(putAbovePageId);
|
||||||
const found2 = children.order.indexOf(currentPageId);
|
const found2 = children.order.indexOf(currentPageId);
|
||||||
|
const margin = found1 < found2 ? 1 : 0;
|
||||||
|
|
||||||
if (found1 < found2) {
|
children.order.splice(found1, 0, currentPageId);
|
||||||
for (let i = found2; i >= found1; i--) {
|
children.order.splice(found2 + margin, 1);
|
||||||
children.order[i] = children.order[i - 1];
|
|
||||||
}
|
|
||||||
children.order[found1] = currentPageId;
|
|
||||||
} else {
|
|
||||||
for (let i = found2; i < found1; i++) {
|
|
||||||
children.order[i] = children.order[i + 1];
|
|
||||||
}
|
|
||||||
children.order[found1 - 1] = currentPageId;
|
|
||||||
}
|
|
||||||
children.save();
|
children.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue