Class

ChangeBuffer (typing/utils)

@ckeditor/ckeditor5-typing/src/utils/changebuffer

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 );

Filtering

Properties

  • readonly

    batch : Batch

    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.

  • readonly

    isLocked : boolean

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

  • readonly

    limit : number

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

  • readonly

    model : Model

    The model instance.

  • readonly

    size : number

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

  • private

    _batch : null | Batch

    The current batch instance.

  • private readonly

    _changeCallback : ( EventInfo<string, unknown>, Batch ) => void

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

  • private

    _isLocked : boolean

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

  • private readonly

    _selectionChangeCallback : () => void

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

  • private

    _size : number

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

Methods

  • 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

  • destroy() → void

    Destroys the buffer.

    Returns

    void
  • 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
  • lock() → void

    Locks the buffer.

    Returns

    void
  • unlock() → void

    Unlocks the buffer.

    Returns

    void
  • private

    _reset( ignoreLock ) → void

    Resets the change buffer.

    Parameters

    ignoreLock : boolean

    Whether internal lock isLocked should be ignored.

    Defaults to false

    Returns

    void