fix move-range tests of moved-moved items

This commit is contained in:
Kevin Jahns 2022-06-16 20:23:34 +02:00
parent b63d22e7db
commit 44499cb9fe
3 changed files with 22 additions and 5 deletions

View File

@ -164,6 +164,7 @@ export class ContentMove {
if (adaptPriority || nextPrio < this.priority || (currMoved != null && nextPrio === this.priority && (currMoved.id.client < item.id.client || (currMoved.id.client === item.id.client && currMoved.id.clock < item.id.clock)))) {
if (currMoved !== null) {
this.overrides.add(currMoved)
transaction._mergeStructs.push(start)
}
maxPriority = math.max(maxPriority, nextPrio)
// was already moved

View File

@ -195,6 +195,19 @@ export class YEvent {
delta.push(lastOp)
}
}
/**
* @param {Item} item
*/
const isMovedByNew = item => {
let moved = item.moved
while (moved != null) {
if (this.adds(moved)) {
return true
}
moved = moved.moved
}
return false
}
for (let item = target._start; ;) {
if (item === currMoveEnd && currMove) {
item = currMove
@ -210,12 +223,12 @@ export class YEvent {
const { start, end } = getMovedCoords(item.content, tr)
currMove = item
currMoveEnd = end
currMoveIsNew = this.adds(item)
currMoveIsNew = this.adds(item) || currMoveIsNew
item = start
continue // do not move to item.right
}
} else if (item.moved !== currMove) {
if (!currMoveIsNew && item.countable && (!item.deleted || this.deletes(item)) && item.moved && !this.adds(item) && this.adds(item.moved) && (this.transaction.prevMoved.get(item) || null) === currMove) {
if (!currMoveIsNew && item.countable && (!item.deleted || this.deletes(item)) && !this.adds(item) && isMovedByNew(item) && (this.transaction.prevMoved.get(item) || null) === currMove) {
if (lastOp === null || lastOp.delete === undefined) {
packOp()
lastOp = { delete: 0 }
@ -237,8 +250,11 @@ export class YEvent {
packOp()
lastOp = { insert: [] }
}
// @todo push items instead (or splice..)
lastOp.insert = lastOp.insert.concat(item.content.getContent())
added.add(item)
if (!currMoveIsNew) {
added.add(item)
}
} else {
if (lastOp === null || lastOp.retain === undefined) {
packOp()

View File

@ -563,10 +563,10 @@ const arrayTransactions = [
return
}
const pos = prng.int32(gen, 0, yarray.length - 1)
const len = prng.int32(gen, 1, math.min(1, yarray.length - pos))
const len = prng.int32(gen, 1, math.min(3, yarray.length - pos))
const _newPosAdj = prng.int32(gen, 0, yarray.length - len)
// make sure that we don't insert in-between the moved range
const newPos = _newPosAdj + (_newPosAdj > yarray.length - len ? len : 0)
const newPos = _newPosAdj + (_newPosAdj > pos ? len : 0)
const oldContent = yarray.toArray()
yarray.moveRange(pos, pos + len - 1, newPos)
const movedValues = oldContent.splice(pos, len)