Class

TreeWalker (engine/view)

@ckeditor/ckeditor5-engine/src/view/treewalker

class

Position iterator class. It allows to iterate forward and backward over the document.

Filtering

Properties

  • readonly

    boundaries : null | Range

    Iterator boundaries.

    When the iterator is walking 'forward' on the end of boundary or is walking 'backward' on the start of boundary, then { done: true } is returned.

    If boundaries are not defined they are set before first and after last child of the root node.

  • readonly

    direction : TreeWalkerDirection

    Walking direction. Defaults 'forward'.

  • readonly

    ignoreElementEnd : boolean

    Flag indicating whether iterator should ignore elementEnd tags. If set to true, walker will not return a parent node of the start position. Each Element will be returned once. When set to false each element might be returned twice: for 'elementStart' and 'elementEnd'.

  • readonly

    position : Position

    Iterator position. If start position is not defined then position depends on direction. If direction is 'forward' position starts form the beginning, when direction is 'backward' position starts from the end.

  • readonly

    shallow : boolean

    Flag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any iterated node will not be returned along with elementEnd tag.

  • readonly

    singleCharacters : boolean

    Flag indicating whether all characters from Text should be returned as one Text or one by one as TextProxy.

  • private readonly

    _boundaryEndParent : null | Node | DocumentFragment

    End boundary parent.

  • private readonly

    _boundaryStartParent : null | Node | DocumentFragment

    Start boundary parent.

  • private

    _position : Position

    Iterator position. If start position is not defined then position depends on direction. If direction is 'forward' position starts form the beginning, when direction is 'backward' position starts from the end.

Methods

  • constructor( options )

    Creates a range iterator. All parameters are optional, but you have to specify either boundaries or startPosition.

    Parameters

    options : TreeWalkerOptions

    Object with configuration.

    Defaults to {}

  • Symbol.iterator() → IterableIterator<TreeWalkerValue>

    Iterable interface.

    Returns

    IterableIterator<TreeWalkerValue>
  • next() → IteratorResult<TreeWalkerValue, undefined>

    Gets the next tree walker's value.

    Returns

    IteratorResult<TreeWalkerValue, undefined>

    Object implementing iterator interface, returning information about taken step.

  • skip( skip ) → void

    Moves position in the direction skipping values as long as the callback function returns true.

    For example:

    walker.skip( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p>
    walker.skip( value => true ); // Move the position to the end: <p>{}foo</p> -> <p>foo</p>[]
    walker.skip( value => false ); // Do not move the position.
    

    Parameters

    skip : ( TreeWalkerValue ) => boolean

    Callback function. Gets TreeWalkerValue and should return true if the value should be skipped or false if not.

    Returns

    void
  • private

    _formatReturnValue( type, item, previousPosition, nextPosition, [ length ] ) → IteratorYieldResult<TreeWalkerValue>

    Format returned data and adjust previousPosition and nextPosition if reach the bound of the Text.

    Parameters

    type : TreeWalkerValueType

    Type of step.

    item : Item

    Item between old and new position.

    previousPosition : Position

    Previous position of iterator.

    nextPosition : Position

    Next position of iterator.

    [ length ] : number

    Length of the item.

    Returns

    IteratorYieldResult<TreeWalkerValue>
  • private

    _next() → IteratorResult<TreeWalkerValue, undefined>

    Makes a step forward in view. Moves the position to the next position and returns the encountered value.

    Returns

    IteratorResult<TreeWalkerValue, undefined>
  • private

    _previous() → IteratorResult<TreeWalkerValue, undefined>

    Makes a step backward in view. Moves the position to the previous position and returns the encountered value.

    Returns

    IteratorResult<TreeWalkerValue, undefined>