Simplify noteContextReorder event call

This commit is contained in:
dymani
2023-06-01 00:48:37 +08:00
parent 735852b3c1
commit 58253567cd
4 changed files with 60 additions and 62 deletions

View File

@@ -451,13 +451,21 @@ export default class TabManager extends Component {
this.tabsUpdate.scheduleUpdate();
}
noteContextReorderEvent({ntxIdsInOrder, mainNtxIdsInOrder}) {
noteContextReorderEvent({ntxIdsInOrder, oldMainNtxId, newMainNtxId}) {
const order = Object.fromEntries(ntxIdsInOrder.map((v, i) => [v, i]));
this.children.sort((a, b) => order[a.ntxId] < order[b.ntxId] ? -1 : 1);
if (!!mainNtxIdsInOrder && mainNtxIdsInOrder.length === this.children.length) {
this.children.forEach((c, i) => c.mainNtxId = mainNtxIdsInOrder[i]);
if (oldMainNtxId && newMainNtxId) {
this.children.forEach(c => {
if (c.ntxId === newMainNtxId) {
// new main context has null mainNtxId
c.mainNtxId = null;
} else if (c.ntxId === oldMainNtxId || c.mainNtxId === oldMainNtxId) {
// old main context or subcontexts all have the new mainNtxId
c.mainNtxId = newMainNtxId;
}
});
}
this.tabsUpdate.scheduleUpdate();