History

Api-class icon class

History keeps the track of all the operations applied to the document.

Properties

  • Chevron-right icon

    lastOperation : undefined | Operation
    readonly

    The last history operation.

  • Chevron-right icon

    version : number

    The 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
  • Chevron-right icon

    _baseVersionToOperationIndex : Map<number, number>
    Lock icon private

    A map that allows retrieving the operations fast based on the given base version.

  • Chevron-right icon

    _gaps : Map<number, number>
    Lock icon private

    The gap pairs kept in the <from,to> format.

    Anytime the history.version is set to a version larger than history.version + 1, a new <lastHistoryVersion, newHistoryVersion> entry is added to the map.

  • Chevron-right icon

    _operations : Array<Operation>
    Lock icon private

    Operations added to the history.

  • Chevron-right icon

    _undoPairs : Map<Operation, Operation>
    Lock icon private

    Holds an information which operation undoes which operation.

    Keys of the map are "undoing operations", that is operations that undone some other operations. For each key, the value is an operation that has been undone by the "undoing operation".

  • Chevron-right icon

    _undoneOperations : Set<Operation>
    Lock icon private

    Holds all undone operations.

  • Chevron-right icon

    _version : number
    Lock icon private

    The history version.

Methods

  • Chevron-right icon

    addOperation( operation ) → void

    Adds 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
  • Chevron-right icon

    getOperation( baseVersion ) → undefined | Operation

    Returns operation from the history that bases on given baseVersion.

    Parameters

    baseVersion : number

    Base version of the operation to get.

    Returns

    undefined | Operation

    Operation with given base version or undefined if there is no such operation in history.

  • Chevron-right icon

    getOperations( [ fromBaseVersion ], toBaseVersion ) → Array<Operation>

    Returns 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 ] : number

    Base version from which operations should be returned (inclusive).

    toBaseVersion : number

    Base version up to which operations should be returned (exclusive). *

    Defaults to ...

    Returns

    Array<Operation>

    History operations for the given range, in chronological order.

  • Chevron-right icon

    getUndoneOperation( undoingOperation ) → undefined | Operation

    For given undoingOperation, returns the operation which has been undone by it.

    Parameters

    undoingOperation : Operation

    Returns

    undefined | Operation

    Operation that has been undone by given undoingOperation or undefined if given undoingOperation is not undoing any other operation.

  • Chevron-right icon

    isUndoingOperation( operation ) → boolean

    Checks whether given operation is undoing any other operation.

    Parameters

    operation : Operation

    Operation to check.

    Returns

    boolean

    true if given operation is undoing any other operation, false otherwise.

  • Chevron-right icon

    isUndoneOperation( operation ) → boolean

    Checks whether given operation has been undone by any other operation.

    Parameters

    operation : Operation

    Operation to check.

    Returns

    boolean

    true if given operation has been undone any other operation, false otherwise.

  • Chevron-right icon

    reset() → void

    Resets the history of operations.

    Returns

    void
  • Chevron-right icon

    setOperationAsUndone( undoneOperation, undoingOperation ) → void

    Marks 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 : Operation

    Operation which is undone by undoingOperation.

    undoingOperation : Operation

    Operation which undoes undoneOperation.

    Returns

    void