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

  • 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.

  • isLocked : Boolean

    readonly

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

  • limit : Number

    readonly

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

  • model : Model

    readonly

    The model instance.

  • size : Number

    readonly

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

  • _batch

    private

    The current batch instance.

  • _changeCallback

    private

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

  • _selectionChangeCallback

    private

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

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

    Destroys the buffer.

  • input( changeCount )

    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.

  • lock()

    Locks the buffer.

  • unlock()

    Unlocks the buffer.

  • _reset( [ ignoreLock ] )

    private

    Resets the change buffer.

    Parameters

    [ ignoreLock ] : Boolean

    Whether internal lock isLocked should be ignored.