1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 06:55:26 +02:00

rewrite to splices

This commit is contained in:
Murod Khaydarov 2019-01-18 10:14:13 +03:00
parent d9dc2bf96b
commit 4299123855
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5

View file

@ -88,18 +88,10 @@ class PagesOrder {
const children = await Model.get(parentPageId);
const found1 = children.order.indexOf(putAbovePageId);
const found2 = children.order.indexOf(currentPageId);
const margin = found1 < found2 ? 1 : 0;
if (found1 < found2) {
for (let i = found2; i >= found1; i--) {
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.order.splice(found1, 0, currentPageId);
children.order.splice(found2 + margin, 1);
children.save();
}
}