Sign up (with export icon)

TypingChangeBuffer

Api-class icon class

Change buffer allows to group atomic changes (like characters that have been typed) into batches.

Batches represent single undo steps, hence changes added to one single batch are undone together.

The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was exceeded (see input), a new batch is created in batch.

To use the change buffer you need to let it know about the number of changes that were added to the batch:

const buffer = new ChangeBuffer( model, LIMIT );

// Later on in your feature:
buffer.batch.insert( pos, insertedCharacters );
buffer.input( insertedCharacters.length );
Copy code

Properties

  • Chevron-right icon

    batch : Batch
    readonly

    The current batch to which a feature should add its operations. Once the size is reached or exceeds the limit, the batch is set to a new instance and the size is reset.

  • Chevron-right icon

    isLocked : boolean
    readonly

    Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.

  • Chevron-right icon

    limit : number
    readonly

    The maximum number of atomic changes which can be contained in one batch.

  • Chevron-right icon

    model : Model
    readonly

    The model instance.

  • Chevron-right icon

    size : number
    readonly

    The number of atomic changes in the buffer. Once it exceeds the limit, the batch is set to a new one.

  • Chevron-right icon

    _batch : null | Batch
    Lock icon private

    The current batch instance.

  • Chevron-right icon

    _changeCallback : ( evt: EventInfo, batch: Batch ) => void
    Lock icon privatereadonly

    The callback to document the change event which later needs to be removed.

  • Chevron-right icon

    _isLocked : boolean
    Lock icon private

    Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.

  • Chevron-right icon

    _selectionChangeCallback : () => void
    Lock icon privatereadonly

    The callback to document selection change:attribute and change:range events which resets the buffer.

  • Chevron-right icon

    _size : number
    Lock icon private

    The number of atomic changes in the buffer. Once it exceeds the limit, the batch is set to a new one.

Methods

  • Chevron-right icon

    constructor( model, limit )

    Creates a new instance of the change buffer.

    Parameters

    model : Model
    limit : number

    The maximum number of atomic changes which can be contained in one batch.

    Defaults to 20

  • Chevron-right icon

    destroy() → void

    Destroys the buffer.

    Returns

    void
  • Chevron-right icon

    input( changeCount ) → void

    The input number of changes into the buffer. Once the size is reached or exceeds the limit, the batch is set to a new instance and the size is reset.

    Parameters

    changeCount : number

    The number of atomic changes to input.

    Returns

    void
  • Chevron-right icon

    lock() → void

    Locks the buffer.

    Returns

    void
  • Chevron-right icon

    unlock() → void

    Unlocks the buffer.

    Returns

    void
  • Chevron-right icon

    _reset( ignoreLock ) → void
    Lock icon private

    Resets the change buffer.

    Parameters

    ignoreLock : boolean

    Whether internal lock isLocked should be ignored.

    Defaults to false

    Returns

    void