Sign up (with export icon)

ModelNodeList

Api-class icon class

Provides an interface to operate on a list of nodes. NodeList is used internally in classes like Element or ModelDocumentFragment.

Properties

  • Chevron-right icon

    length : number
    readonly

    Number of nodes contained inside this node list.

  • Chevron-right icon

    maxOffset : number
    readonly

    Sum of offset sizes of all nodes contained inside this node list.

  • Chevron-right icon

    _nodes : Array<ModelNode>
    Lock icon private

    Nodes contained in this node list.

  • Chevron-right icon

    _offsetToNode : Array<ModelNode>
    Lock icon private

    This array maps numbers (offsets) to node that is placed at that offset.

    This array is similar to _nodes with the difference that one node may occupy multiple consecutive items in the array.

    This array is needed to quickly retrieve a node that is placed at given offset.

Methods

  • Chevron-right icon

    constructor( [ nodes ] )
    internal

    Creates a node list.

    Parameters

    [ nodes ] : Iterable<ModelNode>

    Nodes contained in this node list.

  • Chevron-right icon

    Symbol.iterator() → IterableIterator<ModelNode>

    Iterable interface.

    Iterates over all nodes contained inside this node list.

    Returns

    IterableIterator<ModelNode>
  • Chevron-right icon

    getNode( index ) → null | ModelNode

    Gets the node at the given index. Returns null if incorrect index was passed.

    Parameters

    index : number

    Returns

    null | ModelNode
  • Chevron-right icon

    getNodeAtOffset( offset ) → null | ModelNode

    Gets the node at the given offset. Returns null if incorrect offset was passed.

    Parameters

    offset : number

    Returns

    null | ModelNode
  • Chevron-right icon

    getNodeIndex( node ) → null | number

    Returns an index of the given node or null if given node does not have a parent.

    This is an alias to index.

    Parameters

    node : ModelNode

    Returns

    null | number
  • Chevron-right icon

    getNodeStartOffset( node ) → null | number

    Returns the offset at which given node is placed in its parent or null if given node does not have a parent.

    This is an alias to startOffset.

    Parameters

    node : ModelNode

    Returns

    null | number
  • Chevron-right icon

    indexToOffset( index ) → number

    Converts index to offset in node list.

    Throws CKEditorError model-nodelist-index-out-of-bounds if given index is less than 0 or more than length.

    Parameters

    index : number

    Returns

    number
  • Chevron-right icon

    offsetToIndex( offset ) → number

    Converts offset in node list to index.

    Throws CKEditorError model-nodelist-offset-out-of-bounds if given offset is less than 0 or more than maxOffset.

    Parameters

    offset : number

    Returns

    number
  • Chevron-right icon

    toJSON() → unknown

    Converts NodeList instance to an array containing nodes that were inserted in the node list. Nodes are also converted to their plain object representation.

    Returns

    unknown

    NodeList instance converted to Array.

  • Chevron-right icon

    _insertNodes( index, nodes ) → void
    internal

    Inserts given nodes at given index.

    Parameters

    index : number

    Index at which nodes should be inserted.

    nodes : Iterable<ModelNode>

    Nodes to be inserted.

    Returns

    void
  • Chevron-right icon

    _removeNodes( indexStart, howMany ) → Array<ModelNode>
    internal

    Removes one or more nodes starting at the given index.

    Parameters

    indexStart : number

    Index of the first node to remove.

    howMany : number

    Number of nodes to remove.

    Defaults to 1

    Returns

    Array<ModelNode>

    Array containing removed nodes.

  • Chevron-right icon

    _removeNodesArray( nodes ) → void
    internal

    Removes children nodes provided as an array. These nodes do not need to be direct siblings.

    This method is faster than removing nodes one by one, as it recalculates offsets only once.

    Parameters

    nodes : Array<ModelNode>

    Array of nodes.

    Returns

    void