# TypingChangeBuffer

class

Change buffer allows to group atomic changes (like characters that have been typed) into [batches](module_engine_model_batch-Batch.md).

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`](#function-input)), a new batch is created in [`batch`](#member-batch).

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

```typescript
const buffer = new ChangeBuffer( model, LIMIT );

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L38)

<a id="properties">

## Properties

<a id="member-batch">

### `batch: Batch` _(readonly)_

The current batch to which a feature should add its operations. Once the [`size`](#member-size) is reached or exceeds the [`limit`](#member-limit), the batch is set to a new instance and the size is reset.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L112)

<a id="member-isLocked">

### `isLocked: boolean` _(readonly)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L145)

<a id="member-limit">

### `limit: number` _(readonly)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L47)

<a id="member-model">

### `model: Model` _(readonly)_

The model instance.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L42)

<a id="member-size">

### `size: number` _(readonly)_

The number of atomic changes in the buffer. Once it exceeds the [`limit`](#member-limit), the [batch](#member-batch) is set to a new one.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L124)

<a id="member-_batch">

### `_batch: Batch | null` _(private)_

The current batch instance.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L63)

<a id="member-_changeCallback">

### `_changeCallback: ( evt: EventInfo, batch: Batch ) => void` _(private)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L68)

<a id="member-_isLocked">

### `_isLocked: boolean` _(private)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L52)

<a id="member-_selectionChangeCallback">

### `_selectionChangeCallback: () => void` _(private)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L73)

<a id="member-_size">

### `_size: number` _(private)_

The number of atomic changes in the buffer. Once it exceeds the [`limit`](#member-limit), the [batch](#member-batch) is set to a new one.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L58)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( model, limit )`

Creates a new instance of the change buffer.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L80)

#### Parameters

* `model: Model`

* `limit: number`

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

  Defaults to `20`

<a id="function-destroy">

### `destroy() → void`

Destroys the buffer.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L166)

#### Returns

* `void`

<a id="function-input">

### `input( changeCount ) → void`

The input number of changes into the buffer. Once the [`size`](#member-size) is reached or exceeds the [`limit`](#member-limit), the batch is set to a new instance and the size is reset.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L134)

#### Parameters

* `changeCount: number`

  The number of atomic changes to input.

#### Returns

* `void`

<a id="function-lock">

### `lock() → void`

Locks the buffer.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L152)

#### Returns

* `void`

<a id="function-unlock">

### `unlock() → void`

Unlocks the buffer.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L159)

#### Returns

* `void`

<a id="function-_reset">

### `_reset( ignoreLock ) → void` _(private)_

Resets the change buffer.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-typing/src/utils/changebuffer.ts#L177)

#### Parameters

* `ignoreLock: boolean`

  Whether internal lock [`isLocked`](#member-isLocked) should be ignored.

  Defaults to `false`

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
