fix continuous paired undo redo of arbitrary length
This commit is contained in:
		
							parent
							
								
									645f05b0bb
								
							
						
					
					
						commit
						f113b20188
					
				@ -210,10 +210,21 @@ export const redoItem = (transaction, item, redoitems, itemsToDelete) => {
 | 
			
		||||
      }
 | 
			
		||||
      right = right.right
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @type {Item|null}
 | 
			
		||||
     */
 | 
			
		||||
    let leftTrace = left
 | 
			
		||||
    // Iterate right while right is in itemsToDelete
 | 
			
		||||
    // If it is intended to delete right while item is redone, we can expect that item should replace right.
 | 
			
		||||
    while (left !== null && left.right !== null && left.right !== right && itemsToDelete.findIndex(d => d === /** @type {Item} */ (left).right) >= 0) {
 | 
			
		||||
      left = left.right
 | 
			
		||||
    while (leftTrace !== null && leftTrace.right !== null && leftTrace.right !== right) {
 | 
			
		||||
      if (itemsToDelete.findIndex(d => d === /** @type {Item} */ leftTrace) >= 0) {
 | 
			
		||||
        break
 | 
			
		||||
      }
 | 
			
		||||
      leftTrace = leftTrace.right
 | 
			
		||||
    }
 | 
			
		||||
    if (leftTrace !== null) {
 | 
			
		||||
      left = leftTrace
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  const nextClock = getState(store, ownClientID)
 | 
			
		||||
 | 
			
		||||
@ -358,6 +358,26 @@ export const testUndoNestedUndoIssue = tc => {
 | 
			
		||||
    text.set('blocks', blocks3block)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  const blocks4 = new Y.Array()
 | 
			
		||||
  const blocks4block = new Y.Map()
 | 
			
		||||
  doc.transact(() => {
 | 
			
		||||
    blocks4block.set('text', 'Something Else 2')
 | 
			
		||||
    blocks4.push([blocks4block])
 | 
			
		||||
    text.set('blocks', blocks4block)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  const blocks5 = new Y.Array()
 | 
			
		||||
  const blocks5block = new Y.Map()
 | 
			
		||||
  doc.transact(() => {
 | 
			
		||||
    blocks5block.set('text', 'Something Else 3')
 | 
			
		||||
    blocks5.push([blocks5block])
 | 
			
		||||
    text.set('blocks', blocks5block)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something Else 3' } } })
 | 
			
		||||
  undoManager.undo()
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something Else 2' } } })
 | 
			
		||||
  undoManager.undo()
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something Else' } } })
 | 
			
		||||
  undoManager.undo()
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something' } } })
 | 
			
		||||
@ -371,4 +391,8 @@ export const testUndoNestedUndoIssue = tc => {
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something' } } })
 | 
			
		||||
  undoManager.redo()
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something Else' } } })
 | 
			
		||||
  undoManager.redo()
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something Else 2' } } })
 | 
			
		||||
  undoManager.redo()
 | 
			
		||||
  t.compare(design.toJSON(), { text: { blocks: { text: 'Something Else 3' } } })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user