# MoveOperation

class

Operation to move a range of [model items](module_engine_model_item-ModelItem.md) to given [target position](module_engine_model_position-ModelPosition.md).

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

<a id="properties">

## Properties

<a id="member-affectedSelectable">

### `affectedSelectable: ModelSelectable` _(readonly)_

A selectable that will be affected by the operation after it is executed.

The exact returned parameter differs between operation types.

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

<a id="member-baseVersion">

### `baseVersion: number | null` _(inherited)_

[`version`](module_engine_model_document-ModelDocument.md#member-version) on which operation can be applied. If you try to [apply](module_engine_model_model-Model.md#function-applyOperation) operation with different base version than the [document version](module_engine_model_document-ModelDocument.md#member-version) the [model-document-applyOperation-wrong-version](module_utils_ckeditorerror-CKEditorError.md) error is thrown.

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

<a id="member-batch">

### `batch: Batch | null` _(inherited)_

[Batch](module_engine_model_batch-Batch.md) to which the operation is added or `null` if the operation is not added to any batch yet.

Note, that a [non-document operation](#member-isDocumentOperation) has this property always set to `null`, and is never added to any batch.

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

<a id="member-howMany">

### `howMany: number`

Offset size of moved range.

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

<a id="member-isDocumentOperation">

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

Defines whether operation is executed on attached or detached [items](module_engine_model_item-ModelItem.md).

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

<a id="member-sourcePosition">

### `sourcePosition: ModelPosition`

Position before the first [model item](module_engine_model_item-ModelItem.md) to move.

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

<a id="member-sourceRange">

### `sourceRange: ModelRange` _(readonly)_

Returns the range that is moved by this operation. This is equal to a range starting at [`sourcePosition`](#member-sourcePosition) spanning over [`howMany`](#member-howMany) nodes.

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

<a id="member-targetPosition">

### `targetPosition: ModelPosition`

Position at which moved nodes will be inserted.

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

<a id="member-type">

### `type: 'remove' | 'move' | 'reinsert'` _(readonly)_

Operation type.

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

#### Static properties

<a id="static-member-className">

### `className: string` _(readonly)_

Name of the operation class used for serialization.

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

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( sourcePosition, howMany, targetPosition, baseVersion )`

Creates a move operation.

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

#### Parameters

* `sourcePosition: ModelPosition`

  Position before the first [model item](module_engine_model_item-ModelItem.md) to move.

* `howMany: number`

  Offset size of moved range. Moved range will start from `sourcePosition` and end at `sourcePosition` with offset shifted by `howMany`.

* `targetPosition: ModelPosition`

  Position at which moved nodes will be inserted.

* `baseVersion: number | null`

  Document [`version`](module_engine_model_document-ModelDocument.md#member-version) on which operation can be applied or `null` if the operation operates on detached (non-document) tree.

<a id="function-clone">

### `clone() → MoveOperation`

Creates and returns an operation that has the same parameters as this operation.

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

#### Returns

* `MoveOperation`

<a id="function-getMovedRangeStart">

### `getMovedRangeStart() → ModelPosition`

Returns the start position of the moved range after it got moved. This may be different than [`targetPosition`](#member-targetPosition) in some cases, i.e. when a range is moved inside the same parent but [targetPosition](#member-targetPosition) is after [sourcePosition](#member-sourcePosition).

```
 vv              vv
abcdefg ===> adefbcg
     ^          ^
     targetPos  movedRangeStart
     offset 6   offset 4
```

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

#### Returns

* `ModelPosition`

<a id="function-getReversed">

### `getReversed() → Operation`

See [`Operation#getReversed()`](module_engine_model_operation_operation-Operation.md#function-getReversed).

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

#### Returns

* `Operation`

<a id="function-toJSON">

### `toJSON() → unknown`

Custom toJSON method to solve child-parent circular dependencies.

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

#### Returns

* `unknown`

  Clone of this object with the operation property replaced with string.

<a id="function-_execute">

### `_execute() → void` _(internal)_

Executes the operation - modifications described by the operation properties will be applied to the model tree.

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

#### Returns

* `void`

<a id="function-_validate">

### `_validate() → void` _(internal)_

Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws an error if operation is not valid.

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

#### Returns

* `void`

#### Static methods

<a id="static-function-fromJSON">

### `fromJSON( json, document ) → MoveOperation` _(static)_

Creates `MoveOperation` object from deserialized object, i.e. from parsed JSON string.

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

#### Parameters

* `json: any`

  Deserialized JSON object.

* `document: ModelDocument`

  Document on which this operation will be applied.

#### Returns

* `MoveOperation`

---

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