Sign up (with export icon)

ModelTreeWalker

Api-class iconclass

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

Properties

Methods

  • Chevron-right icon

    constructor( options )

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

    Parameters

    options : ModelTreeWalkerOptions

    Object with configuration.

  • Chevron-right icon

    Symbol.iterator() → IterableIterator<ModelTreeWalkerValue>

    Iterable interface.

    Returns

    IterableIterator<ModelTreeWalkerValue>
  • Chevron-right icon

    jumpTo( position ) → void

    Moves tree walker position to provided position. Tree walker will continue traversing from that position.

    Note: in contrary to skip, this method does not iterate over the nodes along the way. It simply sets the current tree walker position to a new one. From the performance standpoint, it is better to use jumpTo rather than skip.

    If the provided position is before the start boundary, the position will be set to the start boundary. If the provided position is after the end boundary, the position will be set to the end boundary. This is done to prevent the treewalker from traversing outside the boundaries.

    Parameters

    position : ModelPosition

    Position to jump to.

    Returns

    void
  • Chevron-right icon

    next() → IteratorResult<ModelTreeWalkerValue>

    Gets the next tree walker's value.

    Returns

    IteratorResult<ModelTreeWalkerValue>
  • Chevron-right icon

    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' ); // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
    walker.skip( () => true ); // Move the position to the end: <paragraph>[]foo</paragraph> -> <paragraph>foo</paragraph>[]
    walker.skip( () => false ); // Do not move the position.
    
    Copy code

    Parameters

    skip : ( value: ModelTreeWalkerValue ) => boolean

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

    Returns

    void
  • Chevron-right icon

    _next() → IteratorResult<ModelTreeWalkerValue>
    Lock iconprivate

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

    Returns

    IteratorResult<ModelTreeWalkerValue>
  • Chevron-right icon

    _previous() → IteratorResult<ModelTreeWalkerValue>
    Lock iconprivate

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

    Returns

    IteratorResult<ModelTreeWalkerValue>