engine/model/utils/insertobject
Functions
insertObject( model, object, [ selectable ], options = { [options.findOptimalPosition], [options.setSelection] } ) → ModelRangemodule:engine/model/utils/insertobject~insertObjectInserts an object element at a specific position in the editor content.
Note: Use
insertObjectinstead of this function. This function is only exposed to be reusable in algorithms which change theinsertObjectmethod's behavior.Note: For more documentation and examples, see
insertObject.Parameters
model : ModelThe model in context of which the insertion should be performed.
object : ModelElementAn object to be inserted into the model document.
[ selectable ] : null | ModelSelection | ModelDocumentSelectionA selectable where the content should be inserted. If not specified, the current document selection will be used instead.
options : objectAdditional options.
Properties[ options.findOptimalPosition ] : 'auto' | 'after' | 'before'An option that, when set, adjusts the insertion position (relative to
selectableandplaceOrOffset) so that the content ofselectableis not split upon insertion (a.k.a. non-destructive insertion).- When
'auto', the algorithm will decide whether to insert the object before or afterselectableto avoid content splitting. - When
'before', the closest position beforeselectablewill be used that will not result in content splitting. - When
'after', the closest position afterselectablewill 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.
- When
[ options.setSelection ] : 'on' | 'after'An option that, when set, moves the document 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.
- When
Defaults to
{}
Returns
ModelRangeA 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.