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.

  • _affectedEnd : LivePosition | null

    private

    End of the affected range. See getAffectedRange.

  • _affectedStart : LivePosition | null

    private

    Beginning of the affected range. See getAffectedRange.

  • _documentFragment : DocumentFragment

    private

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

  • _documentFragmentPosition : Position

    private

    The current position in the temporary DocumentFragment.

  • _filterAttributesOf : Array.<Node>

    private

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

  • _firstNode : Node

    private

    The reference to the first inserted node.

  • _lastAutoParagraph : Node

    private

    The reference to the last auto paragraph node.

  • _lastNode : Node

    private

    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.

  • _appendToFragment( node )

    private

    Append a node to the temporary DocumentFragment.

    Parameters

    node : Node

    The node to insert.

  • _canMergeLeft( node ) → Boolean

    private

    Checks whether specified node can be merged with previous sibling element.

    Parameters

    node : Node

    The node which could potentially be merged.

    Returns

    Boolean
  • _canMergeRight( node ) → Boolean

    private

    Checks whether specified node can be merged with next sibling element.

    Parameters

    node : Node

    The node which could potentially be merged.

    Returns

    Boolean
  • _checkAndAutoParagraphToAllowedPosition( node ) → Boolean

    private

    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.

  • _checkAndSplitToAllowedPosition( node ) → Boolean

    private

    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.

  • _getAllowedIn( contextElement, childNode ) → Element | null

    private

    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
  • _handleDisallowedNode( node )

    private

    Parameters

    node : Node

    The disallowed node which needs to be handled.

  • _handleNode( node )

    private

    Handles insertion of a single node.

    Parameters

    node : Node
  • _handleObject( node )

    private

    Parameters

    node : Element

    The object element.

  • _insertPartialFragment()

    private

    Inserts the temporary DocumentFragment into the model.

  • _mergeOnLeft()

    private

    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.

  • _mergeOnRight()

    private

    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.

  • _setAffectedBoundaries( position )

    private

    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
  • _tryAutoparagraphing( node )

    private

    Tries wrapping the node in a new paragraph and inserting it this way.

    Parameters

    node : Node

    The node which needs to be autoparagraphed.

  • _updateLastNodeFromAutoParagraph( node )

    private

    Updates the last node after the auto paragraphing.

    Parameters

    node : Node

    The last auto paragraphing node.