adding more sanity checkss to yarray.tests

This commit is contained in:
Kevin Jahns
2021-12-07 12:36:42 +01:00
parent bd47efe0ee
commit 3d31ba8759
7 changed files with 140 additions and 19 deletions

View File

@@ -122,8 +122,17 @@ export class ListIterator {
len += this.rel
this.rel = 0
}
while (item && !this.reachedEnd && (len > 0 || (len === 0 && (!item.countable || item.deleted || item === this.currMoveEnd || item.moved !== this.currMove)))) {
if (item.countable && !item.deleted && item.moved === this.currMove && len > 0) {
while ((!this.reachedEnd || this.currMove !== null) && (len > 0 || (len === 0 && item && (!item.countable || item.deleted || item === this.currMoveEnd || (this.reachedEnd && this.currMoveEnd === null) || item.moved !== this.currMove)))) {
if (item === this.currMoveEnd || (this.currMoveEnd === null && this.reachedEnd && this.currMove)) {
item = /** @type {Item} */ (this.currMove) // we iterate to the right after the current condition
const { start, end, move } = this.movedStack.pop() || { start: null, end: null, move: null }
this.currMove = move
this.currMoveStart = start
this.currMoveEnd = end
this.reachedEnd = false
} else if (item === null) {
break
} else if (item.countable && !item.deleted && item.moved === this.currMove && len > 0) {
len -= item.length
if (len < 0) {
this.rel = item.length + len
@@ -141,13 +150,6 @@ export class ListIterator {
item = start
continue
}
if (item === this.currMoveEnd) {
item = /** @type {Item} */ (this.currMove) // we iterate to the right after the current condition
const { start, end, move } = this.movedStack.pop() || { start: null, end: null, move: null }
this.currMove = move
this.currMoveStart = start
this.currMoveEnd = end
}
if (item.right) {
item = item.right
} else {
@@ -159,6 +161,23 @@ export class ListIterator {
return this
}
/**
* @param {Transaction} tr
*/
reduceMoves (tr) {
let item = this.nextItem
if (item !== null) {
while (item === this.currMoveStart) {
item = /** @type {Item} */ (this.currMove) // we iterate to the left after the current condition
const { start, end, move } = this.movedStack.pop() || { start: null, end: null, move: null }
this.currMove = move
this.currMoveStart = start
this.currMoveEnd = end
}
this.nextItem = item
}
}
/**
* @param {Transaction} tr
* @param {number} len
@@ -249,7 +268,7 @@ export class ListIterator {
this.reachedEnd = true
}
}
if (this.nextItem && !this.reachedEnd && len > 0) {
if (this.nextItem && (!this.reachedEnd || this.currMove !== null) && len > 0) {
this.forward(tr, 0)
}
}
@@ -317,6 +336,7 @@ export class ListIterator {
* @param {Array<AbstractContent>} content
*/
insertContents (tr, content) {
this.reduceMoves(tr)
this._splitRel(tr)
const parent = this.type
const store = tr.doc.store

View File

@@ -75,6 +75,10 @@ export class RelativePosition {
*/
this.assoc = assoc
}
clone () {
return new RelativePosition(this.type, this.tname, this.item, this.assoc)
}
}
/**

View File

@@ -213,7 +213,7 @@ export class YEvent {
continue // do not move to item.right
}
} else if (item.moved !== currMove) {
if (!currMoveIsNew && item.countable && !this.adds(item) && (this.transaction.prevMoved.get(item) || null) === currMove) {
if (!currMoveIsNew && item.countable && item.moved && !this.adds(item) && !this.adds(item.moved) && (this.transaction.prevMoved.get(item) || null) === currMove) {
if (lastOp === null || lastOp.delete === undefined) {
packOp()
lastOp = { delete: 0 }

View File

@@ -308,6 +308,7 @@ export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = U
// Note: Should handle that some operations cannot be applied yet ()
while (true) {
// @todo this incurs an exponential overhead. We could instead only sort the item that changed.
// Write higher clients first ⇒ sort by clientID & clock and remove decoders without content
lazyStructDecoders = lazyStructDecoders.filter(dec => dec.curr !== null)
lazyStructDecoders.sort(