fix move-range tests of moved-moved items
This commit is contained in:
		
							parent
							
								
									b63d22e7db
								
							
						
					
					
						commit
						44499cb9fe
					
				@ -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 (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) {
 | 
					        if (currMoved !== null) {
 | 
				
			||||||
          this.overrides.add(currMoved)
 | 
					          this.overrides.add(currMoved)
 | 
				
			||||||
 | 
					          transaction._mergeStructs.push(start)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        maxPriority = math.max(maxPriority, nextPrio)
 | 
					        maxPriority = math.max(maxPriority, nextPrio)
 | 
				
			||||||
        // was already moved
 | 
					        // was already moved
 | 
				
			||||||
 | 
				
			|||||||
@ -195,6 +195,19 @@ export class YEvent {
 | 
				
			|||||||
              delta.push(lastOp)
 | 
					              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; ;) {
 | 
					          for (let item = target._start; ;) {
 | 
				
			||||||
            if (item === currMoveEnd && currMove) {
 | 
					            if (item === currMoveEnd && currMove) {
 | 
				
			||||||
              item = currMove
 | 
					              item = currMove
 | 
				
			||||||
@ -210,12 +223,12 @@ export class YEvent {
 | 
				
			|||||||
                const { start, end } = getMovedCoords(item.content, tr)
 | 
					                const { start, end } = getMovedCoords(item.content, tr)
 | 
				
			||||||
                currMove = item
 | 
					                currMove = item
 | 
				
			||||||
                currMoveEnd = end
 | 
					                currMoveEnd = end
 | 
				
			||||||
                currMoveIsNew = this.adds(item)
 | 
					                currMoveIsNew = this.adds(item) || currMoveIsNew
 | 
				
			||||||
                item = start
 | 
					                item = start
 | 
				
			||||||
                continue // do not move to item.right
 | 
					                continue // do not move to item.right
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            } else if (item.moved !== currMove) {
 | 
					            } 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) {
 | 
					                if (lastOp === null || lastOp.delete === undefined) {
 | 
				
			||||||
                  packOp()
 | 
					                  packOp()
 | 
				
			||||||
                  lastOp = { delete: 0 }
 | 
					                  lastOp = { delete: 0 }
 | 
				
			||||||
@ -237,8 +250,11 @@ export class YEvent {
 | 
				
			|||||||
                  packOp()
 | 
					                  packOp()
 | 
				
			||||||
                  lastOp = { insert: [] }
 | 
					                  lastOp = { insert: [] }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                // @todo push items instead (or splice..)
 | 
				
			||||||
                lastOp.insert = lastOp.insert.concat(item.content.getContent())
 | 
					                lastOp.insert = lastOp.insert.concat(item.content.getContent())
 | 
				
			||||||
 | 
					                if (!currMoveIsNew) {
 | 
				
			||||||
                  added.add(item)
 | 
					                  added.add(item)
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
              } else {
 | 
					              } else {
 | 
				
			||||||
                if (lastOp === null || lastOp.retain === undefined) {
 | 
					                if (lastOp === null || lastOp.retain === undefined) {
 | 
				
			||||||
                  packOp()
 | 
					                  packOp()
 | 
				
			||||||
 | 
				
			|||||||
@ -563,10 +563,10 @@ const arrayTransactions = [
 | 
				
			|||||||
      return
 | 
					      return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const pos = prng.int32(gen, 0, yarray.length - 1)
 | 
					    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)
 | 
					    const _newPosAdj = prng.int32(gen, 0, yarray.length - len)
 | 
				
			||||||
    // make sure that we don't insert in-between the moved range
 | 
					    // 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()
 | 
					    const oldContent = yarray.toArray()
 | 
				
			||||||
    yarray.moveRange(pos, pos + len - 1, newPos)
 | 
					    yarray.moveRange(pos, pos + len - 1, newPos)
 | 
				
			||||||
    const movedValues = oldContent.splice(pos, len)
 | 
					    const movedValues = oldContent.splice(pos, len)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user