Insertion (engine/model/utils)
@ckeditor/ckeditor5-engine/src/model/utils/insertcontent
Utility class for performing content insertion.
Filtering
Properties
-
canMergeWith : Set
module:engine/model/utils/insertcontent~Insertion#canMergeWith
Elements with which the inserted elements can be merged.
<p>x^</p><p>y</p> + <p>z</p> (can merge to <p>x</p>) <p>x</p><p>^y</p> + <p>z</p> (can merge to <p>y</p>) <p>x^y</p> + <p>z</p> (can merge to <p>xy</p> which will be split during the action, so both its pieces will be added to this set)
-
model : Model
module:engine/model/utils/insertcontent~Insertion#model
The model in context of which the insertion should be performed.
-
The position at which (or near which) the next node will be inserted.
-
Schema of the model.
-
writer : Batch
module:engine/model/utils/insertcontent~Insertion#writer
Batch to which operations will be added.
-
private
_affectedEnd : LivePosition | null
module:engine/model/utils/insertcontent~Insertion#_affectedEnd
End of the affected range. See
getAffectedRange
. -
private
_affectedStart : LivePosition | null
module:engine/model/utils/insertcontent~Insertion#_affectedStart
Beginning of the affected range. See
getAffectedRange
. -
private
_documentFragment : DocumentFragment
module:engine/model/utils/insertcontent~Insertion#_documentFragment
The temporary DocumentFragment used for grouping multiple nodes for single insert operation.
-
private
_documentFragmentPosition : Position
module:engine/model/utils/insertcontent~Insertion#_documentFragmentPosition
The current position in the temporary DocumentFragment.
-
private
_filterAttributesOf : Array.<Node>
module:engine/model/utils/insertcontent~Insertion#_filterAttributesOf
The array of nodes that should be cleaned of not allowed attributes.
-
The reference to the first inserted node.
-
private
_lastAutoParagraph : Node
module:engine/model/utils/insertcontent~Insertion#_lastAutoParagraph
The reference to the last auto paragraph node.
-
The reference to the last inserted node.
Methods
-
destroy()
module:engine/model/utils/insertcontent~Insertion#destroy
Destroys
Insertion
instance. -
getAffectedRange() → Range | null
module:engine/model/utils/insertcontent~Insertion#getAffectedRange
Returns 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. Returns
null
if no changes were done.Returns
Range | null
-
getSelectionRange() → Range | null
module:engine/model/utils/insertcontent~Insertion#getSelectionRange
Returns range to be selected after insertion. Returns
null
if there is no valid range to select after insertion.Returns
Range | null
-
handleNodes( nodes )
module:engine/model/utils/insertcontent~Insertion#handleNodes
-
private
_appendToFragment( node )
module:engine/model/utils/insertcontent~Insertion#_appendToFragment
-
private
_canMergeLeft( node ) → Boolean
module:engine/model/utils/insertcontent~Insertion#_canMergeLeft
Checks whether specified node can be merged with previous sibling element.
Parameters
node : Node
The node which could potentially be merged.
Returns
Boolean
-
private
_canMergeRight( node ) → Boolean
module:engine/model/utils/insertcontent~Insertion#_canMergeRight
Checks whether specified node can be merged with next sibling element.
Parameters
node : Node
The node which could potentially be merged.
Returns
Boolean
-
private
_checkAndAutoParagraphToAllowedPosition( node ) → Boolean
module:engine/model/utils/insertcontent~Insertion#_checkAndAutoParagraphToAllowedPosition
Checks if a node can be inserted in the given position or it would be accepted if a paragraph would be inserted. It also handles inserting the paragraph.
Parameters
node : Node
The node.
Returns
Boolean
Whether an allowed position was found.
false
is returned if the node isn't allowed at the current position or in auto paragraph,true
if was.
-
private
_checkAndSplitToAllowedPosition( node ) → Boolean
module:engine/model/utils/insertcontent~Insertion#_checkAndSplitToAllowedPosition
Parameters
node : Node
Returns
Boolean
Whether an allowed position was found.
false
is returned if the node isn't allowed at any position up in the tree,true
if was.
-
private
_getAllowedIn( contextElement, childNode ) → Element | null
module:engine/model/utils/insertcontent~Insertion#_getAllowedIn
-
private
_handleDisallowedNode( node )
module:engine/model/utils/insertcontent~Insertion#_handleDisallowedNode
-
-
-
private
_insertPartialFragment()
module:engine/model/utils/insertcontent~Insertion#_insertPartialFragment
Inserts the temporary DocumentFragment into the model.
-
Merges the previous sibling of the first node if it should be merged.
After the content was inserted we may try to merge it with its siblings. This should happen only if the selection was in those elements initially.
-
Merges the next sibling of the last node if it should be merged.
After the content was inserted we may try to merge it with its siblings. This should happen only if the selection was in those elements initially.
-
private
_setAffectedBoundaries( position )
module:engine/model/utils/insertcontent~Insertion#_setAffectedBoundaries
Sets
_affectedStart
and_affectedEnd
to the givenposition
. Should be used before a change is done during insertion process to mark the affected range.This method is used before inserting a node or splitting a parent node.
_affectedStart
and_affectedEnd
are also changed during merging, but the logic there is more complicated so it is left out of this function.Parameters
position : Position
-
private
_tryAutoparagraphing( node )
module:engine/model/utils/insertcontent~Insertion#_tryAutoparagraphing
Tries wrapping the node in a new paragraph and inserting it this way.
Parameters
node : Node
The node which needs to be autoparagraphed.
-
private
_updateLastNodeFromAutoParagraph( node )
module:engine/model/utils/insertcontent~Insertion#_updateLastNodeFromAutoParagraph
Updates the last node after the auto paragraphing.
Parameters
node : Node
The last auto paragraphing node.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.