# engine/model/utils/insertobject

module

<a id="functions">

## Functions

<a id="function-insertObject">

### `insertObject( model, object, selectable?, options = { options.findOptimalPosition?, options.setSelection? } ) → ModelRange`

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

**Note:** Use [`insertObject`](module_engine_model_model-Model.md#function-insertObject) instead of this function. This function is only exposed to be reusable in algorithms which change the [`insertObject`](module_engine_model_model-Model.md#function-insertObject) method's behavior.

**Note**: For more documentation and examples, see [`insertObject`](module_engine_model_model-Model.md#function-insertObject).

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

#### Parameters

* `model: Model`

  The model in context of which the insertion should be performed.

* `object: ModelElement`

  An object to be inserted into the model document.

* `selectable?: ModelSelection | ModelDocumentSelection | null`

  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.

* `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 works only 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.

  Defaults to `{}`

#### Returns

* `ModelRange`

  A range which contains all the performed changes. This is a range that, if removed, would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed at the insertion position.

---

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