# Model

class

Editor's data model. Read about the model in the [engine architecture](../framework/architecture/editing-engine.md) guide.

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

<a id="properties">

## Properties

<a id="member-document">

### `document: ModelDocument` _(readonly)_

Model's document.

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

<a id="member-markers">

### `markers: MarkerCollection` _(readonly)_

Model's marker collection.

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

<a id="member-schema">

### `schema: ModelSchema` _(readonly)_

Model's schema.

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

<a id="member-_config">

### `_config?: Config<EngineConfig>` _(internal)_

Stores all configurations specific to editor instance.

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

<a id="member-_currentWriter">

### `_currentWriter: ModelWriter | null` _(private)_

The last created and currently used writer instance.

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

<a id="member-_pendingChanges">

### `_pendingChanges: Array<object>` _(private)_

All callbacks added by [`change`](#function-change) or [`enqueueChange`](#function-enqueueChange:DEFAULT_BATCH) methods waiting to be executed.

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

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( config? )`

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

#### Parameters

* `config?: Config<EngineConfig>`

<a id="function-applyOperation">

### `applyOperation( operation ) → void`

[Decorated](module_utils_observablemixin-Observable.md#function-decorate) function for applying [operations](module_engine_model_operation_operation-Operation.md) to the model.

This is a low-level way of changing the model. It is exposed for very specific use cases (like the undo feature). Normally, to modify the model, you will want to use [`Writer`](module_engine_model_writer-ModelWriter.md). See also [Changing the model](../framework/architecture/editing-engine.md#changing-the-model) section of the [Editing architecture](../framework/architecture/editing-engine.md) guide.

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

#### Parameters

* `operation: Operation`

  The operation to apply.

#### Returns

* `void`

<a id="function-bind:DUAL_BIND">

### `bind( bindProperty1, bindProperty2 ) → ObservableDualBindChain<K1, Model[ K1 ], K2, Model[ K2 ]>` _(inherited)_

Binds [observable properties](#function-set:KEY_VALUE) to other objects implementing the [`Observable`](module_utils_observablemixin-Observable.md) interface.

Read more in the [dedicated](../framework/deep-dive/observables.md#property-bindings) guide covering the topic of property bindings with some additional examples.

Consider two objects: a `button` and an associated `command` (both `Observable`).

A simple property binding could be as follows:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
```

or even shorter:

```typescript
button.bind( 'isEnabled' ).to( command );
```

which works in the following way:

* `button.isEnabled` **instantly equals** `command.isEnabled`,
* whenever `command.isEnabled` changes, `button.isEnabled` will immediately reflect its value.

**Note**: To release the binding, use [`unbind`](module_utils_observablemixin-Observable.md#function-unbind).

You can also "rename" the property in the binding by specifying the new name in the `to()` chain:

```typescript
button.bind( 'isEnabled' ).to( command, 'isWorking' );
```

It is possible to bind more than one property at a time to shorten the code:

```typescript
button.bind( 'isEnabled', 'value' ).to( command );
```

which corresponds to:

```typescript
button.bind( 'isEnabled' ).to( command );
button.bind( 'value' ).to( command );
```

The binding can include more than one observable, combining multiple data sources in a custom callback:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
	( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );
```

Using a custom callback allows processing the value before passing it to the target property:

```typescript
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
```

It is also possible to bind to the same property in an array of observables. To bind a `button` to multiple commands (also `Observables`) so that each and every one of them must be enabled for the button to become enabled, use the following code:

```typescript
button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
	( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );
```

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

#### Type parameters

* * `K1`
  * `K2`

#### Parameters

* `bindProperty1: K1`

  Observable property that will be bound to other observable(s).

* `bindProperty2: K2`

  Observable property that will be bound to other observable(s).

#### Returns

* `ObservableDualBindChain<K1, Model[ K1 ], K2, Model[ K2 ]>`

  The bind chain with the `to()` and `toMany()` methods.

<a id="function-bind:MANY_BIND">

### `bind( bindProperties ) → ObservableMultiBindChain` _(inherited)_

Binds [observable properties](#function-set:KEY_VALUE) to other objects implementing the [`Observable`](module_utils_observablemixin-Observable.md) interface.

Read more in the [dedicated](../framework/deep-dive/observables.md#property-bindings) guide covering the topic of property bindings with some additional examples.

Consider two objects: a `button` and an associated `command` (both `Observable`).

A simple property binding could be as follows:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
```

or even shorter:

```typescript
button.bind( 'isEnabled' ).to( command );
```

which works in the following way:

* `button.isEnabled` **instantly equals** `command.isEnabled`,
* whenever `command.isEnabled` changes, `button.isEnabled` will immediately reflect its value.

**Note**: To release the binding, use [`unbind`](module_utils_observablemixin-Observable.md#function-unbind).

You can also "rename" the property in the binding by specifying the new name in the `to()` chain:

```typescript
button.bind( 'isEnabled' ).to( command, 'isWorking' );
```

It is possible to bind more than one property at a time to shorten the code:

```typescript
button.bind( 'isEnabled', 'value' ).to( command );
```

which corresponds to:

```typescript
button.bind( 'isEnabled' ).to( command );
button.bind( 'value' ).to( command );
```

The binding can include more than one observable, combining multiple data sources in a custom callback:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
	( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );
```

Using a custom callback allows processing the value before passing it to the target property:

```typescript
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
```

It is also possible to bind to the same property in an array of observables. To bind a `button` to multiple commands (also `Observables`) so that each and every one of them must be enabled for the button to become enabled, use the following code:

```typescript
button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
	( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );
```

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

#### Parameters

* `bindProperties: Array<'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'document' | 'destroy' | 'applyOperation' | 'schema' | 'markers' | '_config' | 'enqueueChange' | 'insertContent' | 'insertObject' | 'deleteContent' | 'modifySelection' | 'getSelectedContent' | 'hasContent' | 'canEditAt' | 'createPositionFromPath' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'createBatch' | 'createOperationFromJSON'>`

  Observable properties that will be bound to other observable(s).

#### Returns

* `ObservableMultiBindChain`

  The bind chain with the `to()` and `toMany()` methods.

<a id="function-bind:SINGLE_BIND">

### `bind( bindProperty ) → ObservableSingleBindChain<K, Model[ K ]>` _(inherited)_

Binds [observable properties](#function-set:KEY_VALUE) to other objects implementing the [`Observable`](module_utils_observablemixin-Observable.md) interface.

Read more in the [dedicated](../framework/deep-dive/observables.md#property-bindings) guide covering the topic of property bindings with some additional examples.

Consider two objects: a `button` and an associated `command` (both `Observable`).

A simple property binding could be as follows:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled' );
```

or even shorter:

```typescript
button.bind( 'isEnabled' ).to( command );
```

which works in the following way:

* `button.isEnabled` **instantly equals** `command.isEnabled`,
* whenever `command.isEnabled` changes, `button.isEnabled` will immediately reflect its value.

**Note**: To release the binding, use [`unbind`](module_utils_observablemixin-Observable.md#function-unbind).

You can also "rename" the property in the binding by specifying the new name in the `to()` chain:

```typescript
button.bind( 'isEnabled' ).to( command, 'isWorking' );
```

It is possible to bind more than one property at a time to shorten the code:

```typescript
button.bind( 'isEnabled', 'value' ).to( command );
```

which corresponds to:

```typescript
button.bind( 'isEnabled' ).to( command );
button.bind( 'value' ).to( command );
```

The binding can include more than one observable, combining multiple data sources in a custom callback:

```typescript
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible',
	( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );
```

Using a custom callback allows processing the value before passing it to the target property:

```typescript
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );
```

It is also possible to bind to the same property in an array of observables. To bind a `button` to multiple commands (also `Observables`) so that each and every one of them must be enabled for the button to become enabled, use the following code:

```typescript
button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled',
	( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );
```

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

#### Type parameters

* `K`

#### Parameters

* `bindProperty: K`

  Observable property that will be bound to other observable(s).

#### Returns

* `ObservableSingleBindChain<K, Model[ K ]>`

  The bind chain with the `to()` and `toMany()` methods.

<a id="function-canEditAt">

### `canEditAt( selectable ) → boolean`

Check whether given selectable is at a place in the model where it can be edited (returns `true`) or not (returns `false`).

Should be used instead of [`isReadOnly`](module_core_editor_editor-Editor.md#member-isReadOnly) to check whether a user action can happen at given selectable. It may be decorated and used differently in different environment (e.g. multi-root editor can disable a particular root).

This method is decorated. Although this method accepts any parameter of `Selectable` type, the [`canEditAt` event](#event-canEditAt) is fired with `selectable` normalized to an instance of [`ModelSelection`](module_engine_model_selection-ModelSelection.md) or [`ModelDocumentSelection`](module_engine_model_documentselection-ModelDocumentSelection.md)

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

#### Parameters

* `selectable: ModelSelectable`

#### Returns

* `boolean`

#### Fires

* [canEditAt](#event-canEditAt)

<a id="function-change">

### `change( callback ) → TReturn`

The `change()` method is the primary way of changing the model. You should use it to modify all document nodes (including detached nodes – i.e. nodes not added to the [model document](#member-document)), the [document's selection](module_engine_model_document-ModelDocument.md#member-selection), and [model markers](#member-markers).

```typescript
model.change( writer => {
	writer.insertText( 'foo', paragraph, 'end' );
} );
```

All changes inside the change block use the same [`Batch`](module_engine_model_batch-Batch.md) so they are combined into a single undo step.

```typescript
model.change( writer => {
	writer.insertText( 'foo', paragraph, 'end' ); // foo.

	model.change( writer => {
		writer.insertText( 'bar', paragraph, 'end' ); // foobar.
	} );

	writer.insertText( 'bom', paragraph, 'end' ); // foobarbom.
} );
```

The callback of the `change()` block is executed synchronously.

You can also return a value from the change block.

```typescript
const img = model.change( writer => {
	return writer.createElement( 'img' );
} );
```

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

#### Type parameters

* `TReturn`

  The return type of the provided callback.

#### Parameters

* `callback: ( writer: ModelWriter ) => TReturn`

  Callback function which may modify the model.

#### Returns

* `TReturn`

#### Related:

* [Model#enqueueChange](#function-enqueueChange:DEFAULT_BATCH)

<a id="function-createBatch">

### `createBatch( type? ) → Batch`

Creates a [`Batch`](module_engine_model_batch-Batch.md) instance.

**Note:** In most cases creating a batch instance is not necessary as they are created when using:

* [`change()`](#function-change),
* [`enqueueChange()`](#function-enqueueChange:DEFAULT_BATCH).

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

#### Parameters

* `type?: BatchType`

  [The type](module_engine_model_batch-Batch.md#function-constructor) of the batch.

#### Returns

* `Batch`

<a id="function-createOperationFromJSON">

### `createOperationFromJSON( json ) → Operation`

Creates an operation instance from a JSON object (parsed JSON string).

This is an alias for [`OperationFactory.fromJSON()`](module_engine_model_operation_operationfactory-OperationFactory.md#static-function-fromJSON).

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

#### Parameters

* `json: unknown`

  Deserialized JSON object.

#### Returns

* `Operation`

<a id="function-createPositionAfter">

### `createPositionAfter( item ) → ModelPosition`

Creates a new position after the given [model item](module_engine_model_item-ModelItem.md).

Note: This method is also available as [`Writer#createPositionAfter()`](module_engine_model_writer-ModelWriter.md#function-createPositionAfter).

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

#### Parameters

* `item: ModelItem`

  Item after which the position should be placed.

#### Returns

* `ModelPosition`

<a id="function-createPositionAt">

### `createPositionAt( itemOrPosition, offset? ) → ModelPosition`

Creates position at the given location. The location can be specified as:

* a [position](module_engine_model_position-ModelPosition.md),
* a parent element and offset in that element,
* a parent element and `'end'` (the position will be set at the end of that element),
* a [model item](module_engine_model_item-ModelItem.md) and `'before'` or `'after'` (the position will be set before or after the given model item).

This method is a shortcut to other factory methods such as:

* [`createPositionBefore()`](#function-createPositionBefore),
* [`createPositionAfter()`](#function-createPositionAfter).

Note: This method is also available as [`Writer#createPositionAt()`](module_engine_model_writer-ModelWriter.md#function-createPositionAt),

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

#### Parameters

* `itemOrPosition: ModelDocumentFragment | ModelPosition | ModelItem`

* `offset?: ModelPositionOffset`

  Offset or one of the flags. Used only when first parameter is a [model item](module_engine_model_item-ModelItem.md).

#### Returns

* `ModelPosition`

<a id="function-createPositionBefore">

### `createPositionBefore( item ) → ModelPosition`

Creates a new position before the given [model item](module_engine_model_item-ModelItem.md).

Note: This method is also available as [`Writer#createPositionBefore()`](module_engine_model_writer-ModelWriter.md#function-createPositionBefore).

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

#### Parameters

* `item: ModelItem`

  Item before which the position should be placed.

#### Returns

* `ModelPosition`

<a id="function-createPositionFromPath">

### `createPositionFromPath( root, path, stickiness? ) → ModelPosition`

Creates a position from the given root and path in that root.

Note: This method is also available as [`Writer#createPositionFromPath()`](module_engine_model_writer-ModelWriter.md#function-createPositionFromPath).

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

#### Parameters

* `root: ModelElement | ModelDocumentFragment`

  Root of the position.

* `path: readonly Array<number>`

  Position path. See [`path`](module_engine_model_position-ModelPosition.md#member-path).

* `stickiness?: ModelPositionStickiness`

  Position stickiness. See [`ModelPositionStickiness`](module_engine_model_position-ModelPositionStickiness.md).

#### Returns

* `ModelPosition`

<a id="function-createRange">

### `createRange( start, end? ) → ModelRange`

Creates a range spanning from the `start` position to the `end` position.

Note: This method is also available as [`Writer#createRange()`](module_engine_model_writer-ModelWriter.md#function-createRange):

```typescript
model.change( writer => {
	const range = writer.createRange( start, end );
} );
```

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

#### Parameters

* `start: ModelPosition`

  Start position.

* `end?: ModelPosition`

  End position. If not set, the range will be collapsed to the `start` position.

#### Returns

* `ModelRange`

<a id="function-createRangeIn">

### `createRangeIn( element ) → ModelRange`

Creates a range inside the given element which starts before the first child of that element and ends after the last child of that element.

Note: This method is also available as [`Writer#createRangeIn()`](module_engine_model_writer-ModelWriter.md#function-createRangeIn):

```typescript
model.change( writer => {
	const range = writer.createRangeIn( paragraph );
} );
```

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

#### Parameters

* `element: ModelElement | ModelDocumentFragment`

  Element which is a parent for the range.

#### Returns

* `ModelRange`

<a id="function-createRangeOn">

### `createRangeOn( item ) → ModelRange`

Creates a range that starts before the given [model item](module_engine_model_item-ModelItem.md) and ends after it.

Note: This method is also available on `writer` instance as [`Writer.createRangeOn()`](module_engine_model_writer-ModelWriter.md#function-createRangeOn):

```typescript
model.change( writer => {
	const range = writer.createRangeOn( paragraph );
} );
```

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

#### Parameters

* `item: ModelItem`

#### Returns

* `ModelRange`

<a id="function-createSelection:SELECTABLE">

### `createSelection( selectable?, options? = { options.backward? } ) → ModelSelection`

Creates a new selection instance based on the given [selectable](module_engine_model_selection-ModelSelectable.md) or creates an empty selection if no arguments were passed.

Note: This method is also available as [`Writer#createSelection()`](module_engine_model_writer-ModelWriter.md#function-createSelection:NODE_OFFSET).

```typescript
// Creates empty selection without ranges.
const selection = writer.createSelection();

// Creates selection at the given range.
const range = writer.createRange( start, end );
const selection = writer.createSelection( range );

// Creates selection at the given ranges
const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
const selection = writer.createSelection( ranges );

// Creates selection from the other selection.
// Note: It doesn't copies selection attributes.
const otherSelection = writer.createSelection();
const selection = writer.createSelection( otherSelection );

// Creates selection from the given document selection.
// Note: It doesn't copies selection attributes.
const documentSelection = model.document.selection;
const selection = writer.createSelection( documentSelection );

// Creates selection at the given position.
const position = writer.createPositionFromPath( root, path );
const selection = writer.createSelection( position );

// Additional options (`'backward'`) can be specified as the last argument.

// Creates backward selection.
const selection = writer.createSelection( range, { backward: true } );
```

See also: [`createSelection( node, placeOrOffset, options )`](#function-createSelection:NODE_OFFSET).

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

#### Parameters

* `selectable?: ModelPosition | ModelRange | ModelSelection | ModelDocumentSelection | Iterable<ModelRange, any, any> | null`

* `options?: object`

  Properties

  * `options.backward?: boolean`

#### Returns

* `ModelSelection`

<a id="function-createSelection:NODE_OFFSET">

### `createSelection( selectable, placeOrOffset, options? = { options.backward? } ) → ModelSelection`

Creates a new selection instance based on the given [selectable](module_engine_model_selection-ModelSelectable.md) or creates an empty selection if no arguments were passed.

Note: This method is also available as [`Writer#createSelection()`](module_engine_model_writer-ModelWriter.md#function-createSelection:NODE_OFFSET).

```typescript
// Creates selection at the given offset in the given element.
const paragraph = writer.createElement( 'paragraph' );
const selection = writer.createSelection( paragraph, offset );

// Creates a range inside an element which starts before the
// first child of that element and ends after the last child of that element.
const selection = writer.createSelection( paragraph, 'in' );

// Creates a range on an item which starts before the item and ends
// just after the item.
const selection = writer.createSelection( paragraph, 'on' );

// Additional options (`'backward'`) can be specified as the last argument.

// Creates backward selection.
const selection = writer.createSelection( element, 'in', { backward: true } );
```

See also: [`createSelection( selectable, options )`](#function-createSelection:SELECTABLE).

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

#### Parameters

* `selectable: ModelNode`

* `placeOrOffset: ModelPlaceOrOffset`

* `options?: object`

  Properties

  * `options.backward?: boolean`

#### Returns

* `ModelSelection`

<a id="function-decorate">

### `decorate( methodName ) → void` _(inherited)_

Turns the given methods of this object into event-based ones. This means that the new method will fire an event (named after the method) and the original action will be plugged as a listener to that event.

Read more in the [dedicated](../framework/deep-dive/observables.md#decorating-object-methods) guide covering the topic of decorating methods with some additional examples.

Decorating the method does not change its behavior (it only adds an event), but it allows to modify it later on by listening to the method's event.

For example, to cancel the method execution the event can be [stopped](module_utils_eventinfo-EventInfo.md#member-stop):

```typescript
class Foo extends ObservableMixin() {
	constructor() {
		super();
		this.decorate( 'method' );
	}

	method() {
		console.log( 'called!' );
	}
}

const foo = new Foo();
foo.on( 'method', ( evt ) => {
	evt.stop();
}, { priority: 'high' } );

foo.method(); // Nothing is logged.
```

**Note**: The high [priority](module_utils_priorities-PriorityString.md) listener has been used to execute this particular callback before the one which calls the original method (which uses the "normal" priority).

It is also possible to change the returned value:

```typescript
foo.on( 'method', ( evt ) => {
	evt.return = 'Foo!';
} );

foo.method(); // -> 'Foo'
```

Finally, it is possible to access and modify the arguments the method is called with:

```typescript
method( a, b ) {
	console.log( `${ a }, ${ b }`  );
}

// ...

foo.on( 'method', ( evt, args ) => {
	args[ 0 ] = 3;

	console.log( args[ 1 ] ); // -> 2
}, { priority: 'high' } );

foo.method( 1, 2 ); // -> '3, 2'
```

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

#### Parameters

* `methodName: 'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'document' | 'destroy' | 'applyOperation' | 'schema' | 'markers' | '_config' | 'enqueueChange' | 'insertContent' | 'insertObject' | 'deleteContent' | 'modifySelection' | 'getSelectedContent' | 'hasContent' | 'canEditAt' | 'createPositionFromPath' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'createBatch' | 'createOperationFromJSON'`

  Name of the method to decorate.

#### Returns

* `void`

<a id="function-delegate">

### `delegate( events ) → EmitterMixinDelegateChain` _(inherited)_

Delegates selected events to another [`Emitter`](module_utils_emittermixin-Emitter.md). For instance:

```typescript
emitterA.delegate( 'eventX' ).to( emitterB );
emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
```

then `eventX` is delegated (fired by) `emitterB` and `emitterC` along with `data`:

```typescript
emitterA.fire( 'eventX', data );
```

and `eventY` is delegated (fired by) `emitterC` along with `data`:

```typescript
emitterA.fire( 'eventY', data );
```

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

#### Parameters

* `events: Array<string>`

  Event names that will be delegated to another emitter.

#### Returns

* `EmitterMixinDelegateChain`

<a id="function-deleteContent">

### `deleteContent( selection, options? = { options.direction?, options.doNotAutoparagraph?, options.doNotResetEntireContent?, options.leaveUnmerged?, options.[i: string] } ) → void`

Deletes content of the selection and merge siblings. The resulting selection is always collapsed.

**Note:** For the sake of predictability, the resulting selection should always be collapsed. In cases where a feature wants to modify deleting behavior so selection isn't collapsed (e.g. a table feature may want to keep row selection after pressing `Backspace`), then that behavior should be implemented in the view's listener. At the same time, the table feature will need to modify this method's behavior too, e.g. to "delete contents and then collapse the selection inside the last selected cell" or "delete the row and collapse selection somewhere near". That needs to be done in order to ensure that other features which use `deleteContent()` will work well with tables.

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

#### Parameters

* `selection: ModelSelection | ModelDocumentSelection`

  Selection of which the content should be deleted.

* `options?: object`

  Properties

  * `options.direction?: 'forward' | 'backward'`

    The direction in which the content is being consumed. Deleting backward corresponds to using the `Backspace` key, while deleting content forward corresponds to the `Shift`+`Backspace` keystroke.

  * `options.doNotAutoparagraph?: boolean`

    Whether to create a paragraph if after content deletion selection is moved to a place where text cannot be inserted.

    For example `<paragraph>x</paragraph>[<imageBlock src="foo.jpg"></imageBlock>]` will become:

    * `<paragraph>x</paragraph><paragraph>[]</paragraph>` with the option disabled (`doNotAutoparagraph == false`)
    * `<paragraph>x[]</paragraph>` with the option enabled (`doNotAutoparagraph == true`).

    **Note:** if there is no valid position for the selection, the paragraph will always be created:

    `[<imageBlock src="foo.jpg"></imageBlock>]` -> `<paragraph>[]</paragraph>`.

  * `options.doNotResetEntireContent?: boolean`

    Whether to skip replacing the entire content with a paragraph when the entire content was selected.

    For example `<heading1>[x</heading1><paragraph>y]</paragraph>` will become:

    * `<paragraph>^</paragraph>` with the option disabled (`doNotResetEntireContent == false`)
    * `<heading1>^</heading1>` with enabled (`doNotResetEntireContent == true`)

  * `options.leaveUnmerged?: boolean`

    Whether to merge elements after removing the content of the selection.

    For example `<heading1>x[x</heading1><paragraph>y]y</paragraph>` will become:

    * `<heading1>x^y</heading1>` with the option disabled (`leaveUnmerged == false`)
    * `<heading1>x^</heading1><paragraph>y</paragraph>` with enabled (`leaveUnmerged == true`).

    Note: [object](module_engine_model_schema-ModelSchema.md#function-isObject) and [limit](module_engine_model_schema-ModelSchema.md#function-isLimit) elements will not be merged.

  * `options.[i: string]: unknown`

#### Returns

* `void`

#### Fires

* [deleteContent](#event-deleteContent)

<a id="function-destroy">

### `destroy() → void`

Removes all events listeners set by model instance and destroys [`ModelDocument`](module_engine_model_document-ModelDocument.md).

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

#### Returns

* `void`

<a id="function-enqueueChange:CUSTOM_BATCH">

### `enqueueChange( batchOrType, callback ) → void`

The `enqueueChange()` method performs similar task as the [`change()` method](#function-change), with two major differences.

First, the callback of `enqueueChange()` is executed when all other enqueued changes are done. It might be executed immediately if it is not nested in any other change block, but if it is nested in another (enqueue)change block, it will be delayed and executed after the outermost block.

```typescript
model.change( new Batch(), writer => {
	console.log( 1 );

	model.enqueueChange( new Batch(), writer => {
		console.log( 2 );
	} );

	console.log( 3 );
} ); // Will log: 1, 3, 2.
```

In addition to that, the changes enqueued with `enqueueChange()` will be converted separately from the changes done in the outer `change()` block.

Second, it lets you define the [`Batch`](module_engine_model_batch-Batch.md) into which you want to add your changes. If you want to use default [batch type](module_engine_model_batch-Batch.md#function-constructor), use [`enqueueChange( callback )`](#function-enqueueChange:DEFAULT_BATCH).

```typescript
model.enqueueChange( { isUndoable: false }, writer => {
	writer.insertText( 'foo', paragraph, 'end' );
} );
```

When using the `enqueueChange()` block you can also add some changes to the batch you used before.

```typescript
model.enqueueChange( batch, writer => {
	writer.insertText( 'foo', paragraph, 'end' );
} );
```

In order to make a nested `enqueueChange()` create a single undo step together with the changes done in the outer `change()` block, you can obtain the batch instance from the [writer](module_engine_model_writer-ModelWriter.md#member-batch) of the outer block.

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

#### Parameters

* `batchOrType: Batch | BatchType | undefined`

  A batch or a [batch type](module_engine_model_batch-Batch.md#function-constructor) that should be used in the callback. If not defined, a new batch with the default type will be created.

* `callback: ( writer: ModelWriter ) => unknown`

  Callback function which may modify the model.

#### Returns

* `void`

<a id="function-enqueueChange:DEFAULT_BATCH">

### `enqueueChange( callback ) → void`

The `enqueueChange()` method performs similar task as the [`change()` method](#function-change), with two major differences.

First, the callback of `enqueueChange()` is executed when all other enqueued changes are done. It might be executed immediately if it is not nested in any other change block, but if it is nested in another (enqueue)change block, it will be delayed and executed after the outermost block.

```typescript
model.change( writer => {
	console.log( 1 );

	model.enqueueChange( writer => {
		console.log( 2 );
	} );

	console.log( 3 );
} ); // Will log: 1, 3, 2.
```

In addition to that, the changes enqueued with `enqueueChange()` will be converted separately from the changes done in the outer `change()` block.

By default, a new batch with the default [batch type](module_engine_model_batch-Batch.md#function-constructor) is created. To define the [`Batch`](module_engine_model_batch-Batch.md) into which you want to add your changes, use [`enqueueChange( batchOrType, callback )`](#function-enqueueChange:CUSTOM_BATCH).

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

#### Parameters

* `callback: ( writer: ModelWriter ) => unknown`

  Callback function which may modify the model.

#### Returns

* `void`

<a id="function-fire">

### `fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]` _(inherited)_

Fires an event, executing all callbacks registered for it.

The first parameter passed to callbacks is an [`EventInfo`](module_utils_eventinfo-EventInfo.md) object, followed by the optional `args` provided in the `fire()` method call.

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

#### Type parameters

* `TEvent: extends BaseEvent`

  The type describing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `eventOrInfo: GetNameOrEventInfo<TEvent>`

  The name of the event or `EventInfo` object if event is delegated.

* `args: TEvent[ 'args' ]`

  Additional arguments to be passed to the callbacks.

#### Returns

* `GetEventInfo<TEvent>[ 'return' ]`

  By default the method returns `undefined`. However, the return value can be changed by listeners through modification of the [`evt.return`](module_utils_eventinfo-EventInfo.md#member-return)'s property (the event info is the first param of every callback).

<a id="function-getSelectedContent">

### `getSelectedContent( selection ) → ModelDocumentFragment`

Gets a clone of the selected content.

For example, for the following selection:

```html
<paragraph>x</paragraph>
<blockQuote>
	<paragraph>y</paragraph>
	<heading1>fir[st</heading1>
</blockQuote>
<paragraph>se]cond</paragraph>
<paragraph>z</paragraph>
```

It will return a document fragment with such a content:

```html
<blockQuote>
	<heading1>st</heading1>
</blockQuote>
<paragraph>se</paragraph>
```

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

#### Parameters

* `selection: ModelSelection | ModelDocumentSelection`

  The selection of which content will be returned.

#### Returns

* `ModelDocumentFragment`

#### Fires

* [getSelectedContent](#event-getSelectedContent)

<a id="function-hasContent">

### `hasContent( subject, options = { options.ignoreMarkers?, options.ignoreWhitespaces? } ) → boolean`

Checks whether given `subject` has any meaningful content.

Meaningful content is:

* any text node (`options.ignoreWhitespaces` allows controlling whether this text node must also contain any non-whitespace characters),
* or any [content element](module_engine_model_schema-ModelSchema.md#function-isContent),
* or any [marker](module_engine_model_markercollection-Marker.md) which [affects data](module_engine_model_markercollection-Marker.md#member-_affectsData).

This means that a range containing an empty `<paragraph></paragraph>` is not considered to have a meaningful content. However, a range containing an `<imageBlock></imageBlock>` (which would normally be marked in the schema as an object element) is considered non-empty.

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

#### Parameters

* `subject: ModelElement | ModelDocumentFragment | ModelRange | ModelSelection | ModelDocumentSelection`

  Subject to check if includes meaningful content. Could be a model range, an element, a document fragment, or a selection.

* `options: object`

  Properties

  * `options.ignoreMarkers?: boolean`

    Whether markers should be ignored.

  * `options.ignoreWhitespaces?: boolean`

    Whether text node with whitespaces only should be considered empty.

  Defaults to `{}`

#### Returns

* `boolean`

<a id="function-insertContent">

### `insertContent( content, selectable?, placeOrOffset?, rest ) → ModelRange`

Inserts content at the position in the editor specified by the selection, as one would expect the paste functionality to work.

**Note**: If you want to insert an [object element](../framework/deep-dive/schema.md#object-elements) (e.g. a [widget](module_widget_utils.md#function-toWidget)), see [`insertObject`](#function-insertObject) instead.

This is a high-level method. It takes the [schema](#member-schema) into consideration when inserting the content, clears the given selection's content before inserting nodes and moves the selection to its target position at the end of the process. It can split elements, merge them, wrap bare text nodes with paragraphs, etc. – just like the pasting feature should do.

For lower-level methods see [`Writer`](module_engine_model_writer-ModelWriter.md).

This method, unlike [`Writer`](module_engine_model_writer-ModelWriter.md)'s methods, does not have to be used inside a [`change()` block](#function-change).

#### Conversion and schema

Inserting elements and text nodes into the model is not enough to make CKEditor 5 render that content to the user. CKEditor 5 implements a model-view-controller architecture and what `model.insertContent()` does is only adding nodes to the model. Additionally, you need to define [converters](../framework/architecture/editing-engine.md#conversion) between the model and view and define those nodes in the [schema](../framework/architecture/editing-engine.md#schema).

So, while this method may seem similar to CKEditor 4 `editor.insertHtml()` (in fact, both methods are used for paste-like content insertion), the CKEditor 5 method cannot be use to insert arbitrary HTML unless converters are defined for all elements and attributes in that HTML.

#### Examples

Using `insertContent()` with a manually created model structure:

```typescript
// Let's create a document fragment containing such content as:
//
// <paragraph>foo</paragraph>
// <blockQuote>
//	<paragraph>bar</paragraph>
// </blockQuote>
const docFrag = editor.model.change( writer => {
	const p1 = writer.createElement( 'paragraph' );
	const p2 = writer.createElement( 'paragraph' );
	const blockQuote = writer.createElement( 'blockQuote' );
	const docFrag = writer.createDocumentFragment();

	writer.append( p1, docFrag );
	writer.append( blockQuote, docFrag );
	writer.append( p2, blockQuote );
	writer.insertText( 'foo', p1 );
	writer.insertText( 'bar', p2 );

	return docFrag;
} );

// insertContent() does not have to be used in a change() block. It can, though,
// so this code could be moved to the callback defined above.
editor.model.insertContent( docFrag );
```

Using `insertContent()` with an HTML string converted to a model document fragment (similar to the pasting mechanism):

```typescript
// You can create your own HtmlDataProcessor instance or use editor.data.processor
// if you have not overridden the default one (which is the HtmlDataProcessor instance).
const htmlDP = new HtmlDataProcessor( viewDocument );

// Convert an HTML string to a view document fragment:
const viewFragment = htmlDP.toView( htmlString );

// Convert the view document fragment to a model document fragment
// in the context of $root. This conversion takes the schema into
// account so if, for example, the view document fragment contained a bare text node,
// this text node cannot be a child of $root, so it will be automatically
// wrapped with a <paragraph>. You can define the context yourself (in the second parameter),
// and e.g. convert the content like it would happen in a <paragraph>.
// Note: The clipboard feature uses a custom context called $clipboardHolder
// which has a loosened schema.
const modelFragment = editor.data.toModel( viewFragment );

editor.model.insertContent( modelFragment );
```

By default this method will use the document selection but it can also be used with a position, range or selection instance.

```typescript
// Insert text at the current document selection position.
editor.model.change( writer => {
	editor.model.insertContent( writer.createText( 'x' ) );
} );

// Insert text at a given position - the document selection will not be modified.
editor.model.change( writer => {
	editor.model.insertContent( writer.createText( 'x' ), doc.getRoot(), 2 );

	// Which is a shorthand for:
	editor.model.insertContent( writer.createText( 'x' ), writer.createPositionAt( doc.getRoot(), 2 ) );
} );
```

If you want the document selection to be moved to the inserted content, use the [`setSelection()`](module_engine_model_writer-ModelWriter.md#function-setSelection:NODE_OFFSET) method of the writer after inserting the content:

```typescript
editor.model.change( writer => {
	const paragraph = writer.createElement( 'paragraph' );

	// Insert an empty paragraph at the beginning of the root.
	editor.model.insertContent( paragraph, writer.createPositionAt( editor.model.document.getRoot(), 0 ) );

	// Move the document selection to the inserted paragraph.
	writer.setSelection( paragraph, 'in' );
} );
```

If an instance of the [model selection](module_engine_model_selection-ModelSelection.md) is passed as `selectable`, the new content will be inserted at the passed selection (instead of document selection):

```typescript
editor.model.change( writer => {
	// Create a selection in a paragraph that will be used as a place of insertion.
	const selection = writer.createSelection( paragraph, 'in' );

	// Insert the new text at the created selection.
	editor.model.insertContent( writer.createText( 'x' ), selection );

	// insertContent() modifies the passed selection instance so it can be used to set the document selection.
	// Note: This is not necessary when you passed the document selection to insertContent().
	writer.setSelection( selection );
} );
```

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

#### Parameters

* `content: ModelDocumentFragment | ModelItem`

  The content to insert.

* `selectable?: ModelSelectable`

  The selection into which the content should be inserted. If not provided the current model document selection will be used.

* `placeOrOffset?: ModelPlaceOrOffset`

  To be used when a model item was passed as `selectable`. This param defines a position in relation to that item. at the insertion position.

* `rest: Array<unknown>`

#### Returns

* `ModelRange`

#### Fires

* [insertContent](#event-insertContent)

<a id="function-insertObject">

### `insertObject( element, selectable?, placeOrOffset?, options? = { options.findOptimalPosition?, options.setSelection? }, rest ) → ModelRange`

Inserts an [object element](../framework/deep-dive/schema.md#object-elements) at a specific position in the editor content.

This is a high-level API:

* It takes the [schema](#member-schema) into consideration,
* It clears the content of passed `selectable` before inserting,
* It can move the selection at the end of the process,
* It will copy the selected block's attributes to preserve them upon insertion,
* It can split elements or wrap inline objects with paragraphs if they are not allowed in target position,
* etc.

#### Notes

* If you want to insert a non-object content, see [`insertContent`](#function-insertContent) instead.
* For lower-level API, see [`Writer`](module_engine_model_writer-ModelWriter.md).
* Unlike [`Writer`](module_engine_model_writer-ModelWriter.md), this method does not have to be used inside a [`change()` block](#function-change).
* Inserting object into the model is not enough to make CKEditor 5 render that content to the user. CKEditor 5 implements a model-view-controller architecture and what `model.insertObject()` does is only adding nodes to the model. Additionally, you need to define [converters](../framework/architecture/editing-engine.md#conversion) between the model and view and define those nodes in the [schema](../framework/architecture/editing-engine.md#schema).

#### Examples

Use the following code to insert an object at the current selection and keep the selection on the inserted element:

```typescript
const rawHtmlEmbedElement = writer.createElement( 'rawHtml' );

model.insertObject( rawHtmlEmbedElement, null, null, {
	setSelection: 'on'
} );
```

Use the following code to insert an object at the current selection and nudge the selection after the inserted object:

```typescript
const pageBreakElement = writer.createElement( 'pageBreak' );
 *
model.insertObject( pageBreakElement, null, null, {
	setSelection: 'after'
} );
```

Use the following code to insert an object at the current selection and avoid splitting the content (non-destructive insertion):

```typescript
const tableElement = writer.createElement( 'table' );
 *
model.insertObject( tableElement, null, null, {
	findOptimalPosition: 'auto'
} );
```

Use the following code to insert an object at the specific range (also: replace the content of the range):

```typescript
const tableElement = writer.createElement( 'table' );
const range = model.createRangeOn( model.document.getRoot().getChild( 1 ) );
 *
model.insertObject( tableElement, range );
```

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

#### Parameters

* `element: ModelElement`

  An object to be inserted into the model document.

* `selectable?: ModelSelectable`

  A selectable where the content should be inserted. If not specified, the current [document selection](module_engine_model_document-ModelDocument.md#member-selection) will be used instead.

* `placeOrOffset?: ModelPlaceOrOffset | null`

  Specifies the exact place or offset for the insertion to take place, relative to `selectable`.

* `options?: object`

  Additional options.

  Properties

  * `options.findOptimalPosition?: 'auto' | 'before' | 'after'`

    An option that, when set, adjusts the insertion position (relative to `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).

    * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
    * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
    * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.

    Note that this option only works for block objects. Inline objects are inserted into text and do not split blocks.

  * `options.setSelection?: 'on' | 'after'`

    An option that, when set, moves the [document selection](module_engine_model_document-ModelDocument.md#member-selection) after inserting the object.

    * When `'on'`, the document selection will be set on the inserted object.
    * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no such text node, a paragraph will be created and the document selection will be moved inside it. at the insertion position.

* `rest: Array<unknown>`

#### Returns

* `ModelRange`

<a id="function-listenTo:BASE_EMITTER">

### `listenTo( emitter, event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed when an event is fired in a specific (emitter) object.

Events can be grouped in namespaces using `:`. When namespaced event is fired, it additionally fires all callbacks for that namespace.

```typescript
// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
myEmitter.on( 'myGroup', genericCallback );
myEmitter.on( 'myGroup:myEvent', specificCallback );

// genericCallback is fired.
myEmitter.fire( 'myGroup' );
// both genericCallback and specificCallback are fired.
myEmitter.fire( 'myGroup:myEvent' );
// genericCallback is fired even though there are no callbacks for "foo".
myEmitter.fire( 'myGroup:foo' );
```

An event callback can [stop the event](module_utils_eventinfo-EventInfo.md#member-stop) and set the [return value](module_utils_eventinfo-EventInfo.md#member-return) of the [`fire`](#function-fire) method.

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

#### Type parameters

* `TEvent: extends BaseEvent`

  The type describing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `emitter: Emitter`

  The object that fires the event.

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-modifySelection">

### `modifySelection( selection, options? = { options.direction?, options.treatEmojiAsSingleUnit?, options.unit? } ) → void`

Modifies the selection. Currently, the supported modifications are:

* Extending. The selection focus is moved in the specified `options.direction` with a step specified in `options.unit`. Possible values for `unit` are:
* `'character'` (default) - moves selection by one user-perceived character. In most cases this means moving by one character in `String` sense. However, unicode also defines "combing marks". These are special symbols, that combines with a symbol before it ("base character") to create one user-perceived character. For example, `q̣̇` is a normal letter `q` with two "combining marks": upper dot (`Ux0307`) and lower dot (`Ux0323`). For most actions, i.e. extending selection by one position, it is correct to include both "base character" and all of it's "combining marks". That is why `'character'` value is most natural and common method of modifying selection.
* `'codePoint'` - moves selection by one unicode code point. In contrary to, `'character'` unit, this will insert selection between "base character" and "combining mark", because "combining marks" have their own unicode code points. However, for technical reasons, unicode code points with values above `UxFFFF` are represented in native `String` by two characters, called "surrogate pairs". Halves of "surrogate pairs" have a meaning only when placed next to each other. For example `𨭎` is represented in `String` by `\uD862\uDF4E`. Both `\uD862` and `\uDF4E` do not have any meaning outside the pair (are rendered as ? when alone). Position between them would be incorrect. In this case, selection extension will include whole "surrogate pair".
* `'word'` - moves selection by a whole word.

**Note:** if you extend a forward selection in a backward direction you will in fact shrink it.

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

#### Parameters

* `selection: ModelSelection | ModelDocumentSelection`

  The selection to modify.

* `options?: object`

  Properties

  * `options.direction?: 'forward' | 'backward'`

    The direction in which the selection should be modified.

  * `options.treatEmojiAsSingleUnit?: boolean`

    Whether multi-characer emoji sequences should be handled as single unit.

  * `options.unit?: 'character' | 'codePoint' | 'word'`

    The unit by which selection should be modified.

#### Returns

* `void`

#### Fires

* [modifySelection](#event-modifySelection)

<a id="function-off">

### `off( event, callback ) → void` _(inherited)_

Stops executing the callback on the given event. Shorthand for [`this.stopListening( this, event, callback )`](#function-stopListening:BASE_STOP).

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

#### Parameters

* `event: string`

  The name of the event.

* `callback: Function`

  The function to stop being called.

#### Returns

* `void`

<a id="function-on">

### `on( event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed when an event is fired.

Shorthand for [`this.listenTo( this, event, callback, options )`](#function-listenTo:BASE_EMITTER) (it makes the emitter listen on itself).

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

#### Type parameters

* `TEvent: extends BaseEvent`

  The type descibing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-once">

### `once( event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed on the next time the event is fired only. This is similar to calling [`on`](#function-on) followed by [`off`](#function-off) in the callback.

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

#### Type parameters

* `TEvent: extends BaseEvent`

  The type descibing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-set:OBJECT">

### `set( values ) → void` _(inherited)_

Creates and sets the value of an observable properties of this object. Such a property becomes a part of the state and is observable.

It accepts a single object literal containing key/value pairs with properties to be set.

This method throws the `observable-set-cannot-override` error if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means that `foo.set( 'bar', 1 )` may be slightly slower than `foo.bar = 1`.

In TypeScript, those properties should be declared in class using `declare` keyword. In example:

```typescript
public declare myProp1: number;
public declare myProp2: string;

constructor() {
	this.set( {
		'myProp1: 2,
		'myProp2: 'foo'
	} );
}
```

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

#### Parameters

* `values: object & object`

  An object with `name=>value` pairs.

#### Returns

* `void`

<a id="function-set:KEY_VALUE">

### `set( name, value ) → void` _(inherited)_

Creates and sets the value of an observable property of this object. Such a property becomes a part of the state and is observable.

This method throws the `observable-set-cannot-override` error if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means that `foo.set( 'bar', 1 )` may be slightly slower than `foo.bar = 1`.

In TypeScript, those properties should be declared in class using `declare` keyword. In example:

```typescript
public declare myProp: number;

constructor() {
	this.set( 'myProp', 2 );
}
```

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

#### Type parameters

* `K`

#### Parameters

* `name: K`

  The property's name.

* `value: Model[ K ]`

  The property's value.

#### Returns

* `void`

<a id="function-stopDelegating">

### `stopDelegating( event?, emitter? ) → void` _(inherited)_

Stops delegating events. It can be used at different levels:

* To stop delegating all events.
* To stop delegating a specific event to all emitters.
* To stop delegating a specific event to a specific emitter.

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

#### Parameters

* `event?: string`

  The name of the event to stop delegating. If omitted, stops it all delegations.

* `emitter?: Emitter`

  (requires `event`) The object to stop delegating a particular event to. If omitted, stops delegation of `event` to all emitters.

#### Returns

* `void`

<a id="function-stopListening:BASE_STOP">

### `stopListening( emitter?, event?, callback? ) → void` _(inherited)_

Stops listening for events. It can be used at different levels:

* To stop listening to a specific callback.
* To stop listening to a specific event.
* To stop listening to all events fired by a specific object.
* To stop listening to all events fired by all objects.

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

#### Parameters

* `emitter?: Emitter`

  The object to stop listening to. If omitted, stops it for all objects.

* `event?: string`

  (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it for all events from `emitter`.

* `callback?: Function`

  (Requires the `event`) The function to be removed from the call list for the given `event`.

#### Returns

* `void`

<a id="function-unbind">

### `unbind( unbindProperties ) → void` _(inherited)_

Removes the binding created with [`bind`](#function-bind:SINGLE_BIND).

```typescript
// Removes the binding for the 'a' property.
A.unbind( 'a' );

// Removes bindings for all properties.
A.unbind();
```

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

#### Parameters

* `unbindProperties: Array<'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'document' | 'destroy' | 'applyOperation' | 'schema' | 'markers' | '_config' | 'enqueueChange' | 'insertContent' | 'insertObject' | 'deleteContent' | 'modifySelection' | 'getSelectedContent' | 'hasContent' | 'canEditAt' | 'createPositionFromPath' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'createBatch' | 'createOperationFromJSON'>`

  Observable properties to be unbound. All the bindings will be released if no properties are provided.

#### Returns

* `void`

<a id="function-_rangeHasContent">

### `_rangeHasContent( range, options = { options.ignoreMarkers?, options.ignoreWhitespaces? } ) → boolean` _(private)_

Checks whether given range has any meaningful content.

Helper method for [`hasContent`](#function-hasContent).

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

#### Parameters

* `range: ModelRange`

* `options: object`

  Properties

  * `options.ignoreMarkers?: boolean`
  * `options.ignoreWhitespaces?: boolean`

#### Returns

* `boolean`

<a id="function-_runPendingChanges">

### `_runPendingChanges() → Array<any>` _(private)_

Common part of [`change`](#function-change) and [`enqueueChange`](#function-enqueueChange:DEFAULT_BATCH) which calls callbacks and returns array of values returned by these callbacks.

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

#### Returns

* `Array<any>`

<a id="events">

## Events

<a id="event-_afterChanges">

### `_afterChanges( eventInfo )`

Fired when leaving the outermost [`enqueueChange`](#function-enqueueChange:DEFAULT_BATCH) or [`change`](#function-change) block.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

<a id="event-_beforeChanges">

### `_beforeChanges( eventInfo )`

Fired when entering the outermost [`enqueueChange`](#function-enqueueChange:DEFAULT_BATCH) or [`change`](#function-change) block.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

<a id="event-applyOperation">

### `applyOperation( eventInfo, args )`

Fired every time any [operation](module_engine_model_operation_operation-Operation.md) is applied on the model using [`applyOperation`](#function-applyOperation).

Note that this event is suitable only for very specific use-cases. Use it if you need to listen to every single operation applied on the document. However, in most cases [event-change](module_engine_model_document-ModelDocument.md#event-change) should be used.

A few callbacks are already added to this event by engine internal classes:

* with `highest` priority operation is validated,
* with `normal` priority operation is executed,
* with `low` priority the [`ModelDocument`](module_engine_model_document-ModelDocument.md) updates its version,
* with `low` priority [`ModelLivePosition`](module_engine_model_liveposition-ModelLivePosition.md) and [`ModelLiveRange`](module_engine_model_liverange-ModelLiveRange.md) update themselves.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: Parameters<TObservable[ TName ]>`

  Arguments of the `applyOperation` which is an array with a single element - applied [operation](module_engine_model_operation_operation-Operation.md).

<a id="event-canEditAt">

### `canEditAt( eventInfo, args )`

Event fired when [`canEditAt`](#function-canEditAt) method is called.

The [default action of that method](#function-canEditAt) is implemented as a listener to this event, so it can be fully customized by the features.

Although the original method accepts any parameter of `Selectable` type, this event is fired with `selectable` normalized to an instance of [`ModelSelection`](module_engine_model_selection-ModelSelection.md) or [`ModelDocumentSelection`](module_engine_model_documentselection-ModelDocumentSelection.md).

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: [ selectable?: ModelSelection | ModelDocumentSelection ]`

  The arguments passed to the original method.

<a id="event-change:%7Bproperty%7D">

### `change:{property}( eventInfo, name, value, oldValue )` _(inherited)_

Fired when a property changed value.

```typescript
observable.set( 'prop', 1 );

observable.on<ObservableChangeEvent<number>>( 'change:prop', ( evt, propertyName, newValue, oldValue ) => {
	console.log( `${ propertyName } has changed from ${ oldValue } to ${ newValue }` );
} );

observable.prop = 2; // -> 'prop has changed from 1 to 2'
```

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  The property name.

* `value: TValue`

  The new property value.

* `oldValue: TValue`

  The previous property value.

<a id="event-deleteContent">

### `deleteContent( eventInfo, args )`

Event fired when [`deleteContent`](#function-deleteContent) method is called.

The [default action of that method](#function-deleteContent) is implemented as a listener to this event, so it can be fully customized by the features.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: Parameters<TObservable[ TName ]>`

  The arguments passed to the original method.

<a id="event-getSelectedContent">

### `getSelectedContent( eventInfo, args )`

Event fired when [`getSelectedContent`](#function-getSelectedContent) method is called.

The [default action of that method](#function-getSelectedContent) is implemented as a listener to this event, so it can be fully customized by the features.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: Parameters<TObservable[ TName ]>`

  The arguments passed to the original method.

<a id="event-insertContent">

### `insertContent( eventInfo, args )`

Event fired when [`insertContent`](#function-insertContent) method is called.

The [default action of that method](#function-insertContent) is implemented as a listener to this event so it can be fully customized by the features.

**Note** The `selectable` parameter for the [`insertContent`](#function-insertContent) is optional. When `undefined` value is passed the method uses [document selection](module_engine_model_document-ModelDocument.md#member-selection).

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: [ content: ModelItem | ModelDocumentFragment, selectable?: ModelSelection | ModelDocumentSelection, rest: Array<unknown> ]`

  The arguments passed to the original method.

<a id="event-insertObject">

### `insertObject( eventInfo, args )`

Event fired when the [`insertObject`](#function-insertObject) method is called.

The [default action of that method](#function-insertObject) is implemented as a listener to this event so it can be fully customized by the features.

**Note** The `selectable` parameter for the [`insertObject`](#function-insertObject) is optional. When `undefined` value is passed the method uses [document selection](module_engine_model_document-ModelDocument.md#member-selection).

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: [ element: ModelElement, selectable?: ModelSelection | ModelDocumentSelection | null, options?: object, rest: Array<unknown> ]`

  The arguments passed to the original method.

<a id="event-modifySelection">

### `modifySelection( eventInfo, args )`

Event fired when [`modifySelection`](#function-modifySelection) method is called.

The [default action of that method](#function-modifySelection) is implemented as a listener to this event, so it can be fully customized by the features.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `args: Parameters<TObservable[ TName ]>`

  The arguments passed to the original method.

<a id="event-set:%7Bproperty%7D">

### `set:{property}( eventInfo, name, value, oldValue )` _(inherited)_

Fired when a property value is going to be set but is not set yet (before the `change` event is fired).

You can control the final value of the property by using the [event's `return` property](module_utils_eventinfo-EventInfo.md#member-return).

```typescript
observable.set( 'prop', 1 );

observable.on<ObservableSetEvent<number>>( 'set:prop', ( evt, propertyName, newValue, oldValue ) => {
	console.log( `Value is going to be changed from ${ oldValue } to ${ newValue }` );
	console.log( `Current property value is ${ observable[ propertyName ] }` );

	// Let's override the value.
	evt.return = 3;
} );

observable.on<ObservableChangeEvent<number>>( 'change:prop', ( evt, propertyName, newValue, oldValue ) => {
	console.log( `Value has changed from ${ oldValue } to ${ newValue }` );
} );

observable.prop = 2; // -> 'Value is going to be changed from 1 to 2'
					 // -> 'Current property value is 1'
					 // -> 'Value has changed from 1 to 3'
```

**Note:** The event is fired even when the new value is the same as the old value.

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

#### Parameters

* `eventInfo: EventInfo`

  An object containing information about the fired event.

* `name: string`

  The property name.

* `value: TValue`

  The new property value.

* `oldValue: TValue`

  The previous property value.

---

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