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.

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, parentContext )

    Handles insertion of a set of nodes.

    Parameters

    nodes : Iterable.<Node>

    Nodes to insert.

    parentContext : Object

    Context in which parent of these nodes was supposed to be inserted. If the parent context is passed it means that the parent element was stripped (was not allowed).

  • _canMergeLeft( node, context ) → Boolean

    private

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

    Parameters

    node : Node

    The node which could potentially be merged.

    context : Object

    Returns

    Boolean
  • _canMergeRight( node, context ) → Boolean

    private

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

    Parameters

    node : Node

    The node which could potentially be merged.

    context : Object

    Returns

    Boolean
  • _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( node, element ) → Element | null

    private

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

    Parameters

    node : Node

    The node to check.

    element : Element

    The element in which the node's correctness should be checked.

    Returns

    Element | null
  • _handleDisallowedNode( node, context )

    private

    Parameters

    node : Node

    The disallowed node which needs to be handled.

    context : Object
  • _handleNode( node, context = { context.isFirst, context.isLast } )

    private

    Handles insertion of a single node.

    Parameters

    node : Node
    context : Object
    Properties
    context.isFirst : Boolean

    Whether the given node is the first one in the content to be inserted.

    context.isLast : Boolean

    Whether the given node is the last one in the content to be inserted.

  • _handleObject( node, context )

    private

    Parameters

    node : Element

    The object element.

    context : Object
  • _insert( node )

    private

    Parameters

    node : Node

    The node to insert.

  • _mergeSiblingsOf( node, context )

    private

    Parameters

    node : Node

    The node which could potentially be merged.

    context : Object
  • _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, context )

    private

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

    Parameters

    node : Node

    The node which needs to be autoparagraphed.

    context : Object