History
History keeps the track of all the operations applied to the document.
Properties
-
lastOperation : undefined | Operationreadonlymodule:engine/model/history~History#lastOperationThe last history operation.
-
version : numbermodule:engine/model/history~History#versionThe version of the last operation in the history.
The history version is incremented automatically when a new operation is added to the history. Setting the version manually should be done only in rare circumstances when a gap is planned between history versions. When doing so, a gap will be created and the history will accept adding an operation with base version equal to the new history version.
Parameters
version : number
-
_baseVersionToOperationIndex : Map<number, number>privatemodule:engine/model/history~History#_baseVersionToOperationIndexA map that allows retrieving the operations fast based on the given base version.
-
_gaps : Map<number, number>privatemodule:engine/model/history~History#_gapsThe gap pairs kept in the <from,to> format.
Anytime the
history.versionis set to a version larger thanhistory.version + 1, a new <lastHistoryVersion, newHistoryVersion> entry is added to the map. -
_operations : Array<Operation>privatemodule:engine/model/history~History#_operationsOperations added to the history.
-
_undoPairs : Map<Operation, Operation>privatemodule:engine/model/history~History#_undoPairs -
_undoneOperations : Set<Operation>privatemodule:engine/model/history~History#_undoneOperationsHolds all undone operations.
-
_version : numberprivatemodule:engine/model/history~History#_versionThe history version.
Methods
-
addOperation( operation ) → voidmodule:engine/model/history~History#addOperationAdds an operation to the history and increments the history version.
The operation's base version should be equal to the history version. Otherwise an error is thrown.
Parameters
operation : Operation
Returns
void
-
getOperation( baseVersion ) → undefined | Operationmodule:engine/model/history~History#getOperationReturns operation from the history that bases on given
baseVersion.Parameters
baseVersion : numberBase version of the operation to get.
Returns
undefined | OperationOperation with given base version or
undefinedif there is no such operation in history.
-
getOperations( [ fromBaseVersion ], toBaseVersion ) → Array<Operation>module:engine/model/history~History#getOperationsReturns operations from the given range of operation base versions that were added to the history.
Note that there may be gaps in operations base versions.
Parameters
[ fromBaseVersion ] : numberBase version from which operations should be returned (inclusive).
toBaseVersion : numberBase version up to which operations should be returned (exclusive). *
Defaults to
...
Returns
Array<Operation>History operations for the given range, in chronological order.
-
getUndoneOperation( undoingOperation ) → undefined | Operationmodule:engine/model/history~History#getUndoneOperation -
isUndoingOperation( operation ) → booleanmodule:engine/model/history~History#isUndoingOperationChecks whether given
operationis undoing any other operation.Parameters
operation : OperationOperation to check.
Returns
booleantrueif givenoperationis undoing any other operation,falseotherwise.
-
isUndoneOperation( operation ) → booleanmodule:engine/model/history~History#isUndoneOperationChecks whether given
operationhas been undone by any other operation.Parameters
operation : OperationOperation to check.
Returns
booleantrueif givenoperationhas been undone any other operation,falseotherwise.
-
reset() → voidmodule:engine/model/history~History#reset -
setOperationAsUndone( undoneOperation, undoingOperation ) → voidmodule:engine/model/history~History#setOperationAsUndoneMarks in history that one operation is an operation that is undoing the other operation. By marking operation this way, history is keeping more context information about operations, which helps in operational transformation.
Parameters
undoneOperation : OperationOperation which is undone by
undoingOperation.undoingOperation : OperationOperation which undoes
undoneOperation.
Returns
void