engine/model/utils/insertcontent
Functions
insertContent( model, content, [ selectable ] ) → ModelRangeinternalmodule:engine/model/utils/insertcontent~insertContentInserts content into the editor (specified selection) as one would expect the paste functionality to work.
It takes care of removing the selected content, splitting elements (if needed), inserting elements and merging elements appropriately.
Some examples:
<p>x^</p> + <p>y</p> => <p>x</p><p>y</p> => <p>xy[]</p> <p>x^y</p> + <p>z</p> => <p>x</p>^<p>y</p> + <p>z</p> => <p>x</p><p>z</p><p>y</p> => <p>xz[]y</p> <p>x^y</p> + <img /> => <p>x</p>^<p>y</p> + <img /> => <p>x</p><img /><p>y</p> <p>x</p><p>^</p><p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p> (no merging) <p>x</p>[<img />]<p>z</p> + <p>y</p> => <p>x</p>^<p>z</p> + <p>y</p> => <p>x</p><p>y[]</p><p>z</p>Copy codeIf an instance of
ModelSelectionis passed asselectableit will be modified to the insertion selection (equal to a range to be selected after insertion).If
selectableis not passed, the content will be inserted using the current selection of the model document.Note: Use
insertContentinstead of this function. This function is only exposed to be reusable in algorithms which change theinsertContentmethod's behavior.Parameters
model : ModelThe model in context of which the insertion should be performed.
content : ModelDocumentFragment | ModelItemThe content to insert.
[ selectable ] : ModelSelection | ModelDocumentSelectionSelection into which the content should be inserted.
Returns
ModelRangeRange 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
insertContent, returns a range collapsed at the insertion position.