diff --git a/src/js/timeline.js b/src/js/timeline.js index 4a55406..8a79d00 100644 --- a/src/js/timeline.js +++ b/src/js/timeline.js @@ -144,22 +144,25 @@ class ReactiveTimeline extends ElemJS { } tryAddGroups(event, indices) { + const createGroupAt = i => { + // if (printed++ < 100) console.log("tryadd success, created group") + if (i === -1) { + // here, -1 means at the start, before the first group + i = 0 // jank but it does the trick + } + if (event.canGroup()) { + const group = new EventGroup(this, [event]) + this.list.splice(i, 0, group) + this.childAt(i, group) + event.setGroup(group) + } else { + this.list.splice(i, 0, event) + this.childAt(i, event) + } + } const success = indices.some(i => { if (!this.list[i]) { - // if (printed++ < 100) console.log("tryadd success, created group") - if (i === -1) { - // here, -1 means at the start, before the first group - i = 0 // jank but it does the trick - } - if (event.canGroup()) { - const group = new EventGroup(this, [event]) - this.list.splice(i, 0, group) - this.childAt(i, group) - event.setGroup(group) - } else { - this.list.splice(i, 0, event) - this.childAt(i, event) - } + createGroupAt(i) return true } else if (event.canGroup() && this.list[i] && this.list[i].canGroup() && this.list[i].data.sender === event.data.sender) { // if (printed++ < 100) console.log("tryadd success, using existing group") @@ -167,7 +170,8 @@ class ReactiveTimeline extends ElemJS { return true } }) - if (!success) console.log("tryadd failure", indices, this.list.map(l => l.data.sender), event.data) + // if (!success) console.log("tryadd failure", indices, this.list.map(l => l.data.sender), event.data) // I believe all the bugs are now fixed. Lol. + if (!success) createGroupAt(indices[0]) } removeGroup(group) {