Class

Insertion (engine/model/utils)

@ckeditor/ckeditor5-engine/src/model/utils/insertcontent

class private

Utility class for performing content insertion.

Filtering

Properties

  • canMergeWith : Set

    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

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

  • position : Position

    The position at which (or near which) the next node will be inserted.

  • schema : Schema

    Schema of the model.

  • writer : Batch

    Batch to which operations will be added.

  • private

    _affectedEnd : LivePosition | null

    End of the affected range. See getAffectedRange.

  • private

    _affectedStart : LivePosition | null

    Beginning of the affected range. See getAffectedRange.

  • private

    _documentFragment : DocumentFragment

    The temporary DocumentFragment used for grouping multiple nodes for single insert operation.

  • private

    _documentFragmentPosition : Position

    The current position in the temporary DocumentFragment.

  • private

    _filterAttributesOf : Array.<Node>

    The array of nodes that should be cleaned of not allowed attributes.

  • private

    _firstNode : Node

    The reference to the first inserted node.

  • private

    _lastAutoParagraph : Node

    The reference to the last auto paragraph node.

  • private

    _lastNode : Node

    The reference to the last inserted node.

Methods

  • destroy()

    Destroys Insertion instance.

  • getAffectedRange() → Range | null

    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

    Returns range to be selected after insertion. Returns null if there is no valid range to select after insertion.

    Returns

    Range | null
  • handleNodes( nodes )

    Handles insertion of a set of nodes.

    Parameters

    nodes : Iterable.<Node>

    Nodes to insert.

  • private

    _appendToFragment( node )

    Append a node to the temporary DocumentFragment.

    Parameters

    node : Node

    The node to insert.

  • private

    _canMergeLeft( node ) → Boolean

    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

    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

    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

    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

    Gets the element in which the given node is allowed. It checks the passed element and all its ancestors.

    Parameters

    contextElement : Element

    The element in which context the node should be checked.

    childNode : Node

    The node to check.

    Returns

    Element | null
  • private

    _handleDisallowedNode( node )

    Parameters

    node : Node

    The disallowed node which needs to be handled.

  • private

    _handleNode( node )

    Handles insertion of a single node.

    Parameters

    node : Node
  • private

    _handleObject( node )

    Parameters

    node : Element

    The object element.

  • private

    _insertPartialFragment()

    Inserts the temporary DocumentFragment into the model.

  • private

    _mergeOnLeft()

    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.

  • private

    _mergeOnRight()

    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 )

    Sets _affectedStart and _affectedEnd to the given position. 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 )

    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 )

    Updates the last node after the auto paragraphing.

    Parameters

    node : Node

    The last auto paragraphing node.