undo fixes for consecutive undo-redo
This commit is contained in:
		
							parent
							
								
									641f426339
								
							
						
					
					
						commit
						1b0e3659c3
					
				@ -77,6 +77,7 @@ export default class YXmlText extends YText {
 | 
				
			|||||||
    return this._dom
 | 
					    return this._dom
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  _delete (y, createDelete) {
 | 
					  _delete (y, createDelete) {
 | 
				
			||||||
 | 
					    console.log('deleting text type..', this._id)
 | 
				
			||||||
    this._unbindFromDom()
 | 
					    this._unbindFromDom()
 | 
				
			||||||
    super._delete(y, createDelete)
 | 
					    super._delete(y, createDelete)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -73,6 +73,7 @@ export default class UndoManager {
 | 
				
			|||||||
    this._scope = scope
 | 
					    this._scope = scope
 | 
				
			||||||
    this._undoing = false
 | 
					    this._undoing = false
 | 
				
			||||||
    this._redoing = false
 | 
					    this._redoing = false
 | 
				
			||||||
 | 
					    this._lastTransactionWasUndo = false
 | 
				
			||||||
    const y = scope._y
 | 
					    const y = scope._y
 | 
				
			||||||
    this.y = y
 | 
					    this.y = y
 | 
				
			||||||
    y.on('afterTransaction', (y, transaction, remote) => {
 | 
					    y.on('afterTransaction', (y, transaction, remote) => {
 | 
				
			||||||
@ -80,7 +81,12 @@ export default class UndoManager {
 | 
				
			|||||||
        let reverseOperation = new ReverseOperation(y, transaction)
 | 
					        let reverseOperation = new ReverseOperation(y, transaction)
 | 
				
			||||||
        if (!this._undoing) {
 | 
					        if (!this._undoing) {
 | 
				
			||||||
          let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null
 | 
					          let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null
 | 
				
			||||||
          if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) {
 | 
					          if (
 | 
				
			||||||
 | 
					            this._redoing === false &&
 | 
				
			||||||
 | 
					            this._lastTransactionWasUndo === false &&
 | 
				
			||||||
 | 
					            lastUndoOp !== null &&
 | 
				
			||||||
 | 
					            reverseOperation.created - lastUndoOp.created <= options.captureTimeout
 | 
				
			||||||
 | 
					          ) {
 | 
				
			||||||
            lastUndoOp.created = reverseOperation.created
 | 
					            lastUndoOp.created = reverseOperation.created
 | 
				
			||||||
            if (reverseOperation.toState !== null) {
 | 
					            if (reverseOperation.toState !== null) {
 | 
				
			||||||
              lastUndoOp.toState = reverseOperation.toState
 | 
					              lastUndoOp.toState = reverseOperation.toState
 | 
				
			||||||
@ -90,12 +96,14 @@ export default class UndoManager {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)
 | 
					            reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
 | 
					            this._lastTransactionWasUndo = false
 | 
				
			||||||
            this._undoBuffer.push(reverseOperation)
 | 
					            this._undoBuffer.push(reverseOperation)
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          if (!this._redoing) {
 | 
					          if (!this._redoing) {
 | 
				
			||||||
            this._redoBuffer = []
 | 
					            this._redoBuffer = []
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
					          this._lastTransactionWasUndo = true
 | 
				
			||||||
          this._redoBuffer.push(reverseOperation)
 | 
					          this._redoBuffer.push(reverseOperation)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user