# History

class

`History` keeps the track of all the operations applied to the [document](module_engine_model_document-ModelDocument.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L17)

<a id="properties">

## Properties

<a id="member-lastOperation">

### `lastOperation: Operation | undefined` _(readonly)_

The last history operation.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L80)

<a id="member-version">

### `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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L63)

#### Parameters

* `version: number`

<a id="member-_baseVersionToOperationIndex">

### `_baseVersionToOperationIndex: Map<number, number>` _(private)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L40)

<a id="member-_gaps">

### `_gaps: Map<number, number>` _(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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L53)

<a id="member-_operations">

### `_operations: Array<Operation>` _(private)_

Operations added to the history.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L21)

<a id="member-_undoPairs">

### `_undoPairs: Map<Operation, Operation>` _(private)_

Holds an information which [operation](module_engine_model_operation_operation-Operation.md) undoes which [operation](module_engine_model_operation_operation-Operation.md).

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L30)

<a id="member-_undoneOperations">

### `_undoneOperations: Set<Operation>` _(private)_

Holds all undone operations.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L35)

<a id="member-_version">

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

The history version.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L45)

<a id="methods">

## Methods

<a id="function-addOperation">

### `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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L89)

#### Parameters

* `operation: Operation`

#### Returns

* `void`

<a id="function-getOperation">

### `getOperation( baseVersion ) → Operation | undefined`

Returns operation from the history that bases on given `baseVersion`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L183)

#### Parameters

* `baseVersion: number`

  Base version of the operation to get.

#### Returns

* `Operation | undefined`

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

<a id="function-getOperations">

### `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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L119)

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

<a id="function-getUndoneOperation">

### `getUndoneOperation( undoingOperation ) → Operation | undefined`

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L231)

#### Parameters

* `undoingOperation: Operation`

#### Returns

* `Operation | undefined`

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

<a id="function-isUndoingOperation">

### `isUndoingOperation( operation ) → boolean`

Checks whether given `operation` is undoing any other operation.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L211)

#### Parameters

* `operation: Operation`

  Operation to check.

#### Returns

* `boolean`

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

<a id="function-isUndoneOperation">

### `isUndoneOperation( operation ) → boolean`

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L221)

#### Parameters

* `operation: Operation`

  Operation to check.

#### Returns

* `boolean`

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

<a id="function-reset">

### `reset() → void`

Resets the history of operations.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L238)

#### Returns

* `void`

<a id="function-setOperationAsUndone">

### `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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/history.ts#L200)

#### Parameters

* `undoneOperation: Operation`

  Operation which is undone by `undoingOperation`.

* `undoingOperation: Operation`

  Operation which undoes `undoneOperation`.

#### Returns

* `void`

---

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