Sign up (with export icon)

ModelTreeWalker

Api-class icon class

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

Properties

  • Chevron-right icon

    boundaries : null | ModelRange
    readonly

    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.

  • Chevron-right icon

    Walking direction. Defaults 'forward'.

  • Chevron-right icon

    ignoreElementEnd : boolean
    readonly

    Flag indicating whether iterator should ignore elementEnd tags. If the option is true walker will not return a parent node of the start position. If this option is true each ModelElement will be returned once, while if the option is false they might be returned twice: for 'elementStart' and 'elementEnd'.

  • Chevron-right icon

    Iterator position. This is always static position, even if the initial position was a live 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.

  • Chevron-right icon

    shallow : boolean
    readonly

    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.

  • Chevron-right icon

    singleCharacters : boolean
    readonly

    Flag indicating whether all consecutive characters with the same attributes should be returned as one ModelTextProxy (true) or one by one (false).

  • Chevron-right icon

    End boundary cached for optimization purposes.

  • Chevron-right icon

    Start boundary cached for optimization purposes.

  • Chevron-right icon

    _position : ModelPosition
    Lock icon private

    Iterator position. This is always static position, even if the initial position was a live 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.

  • Chevron-right icon

    Parent of the most recently visited node. Cached for optimization purposes.

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 icon private

    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 icon private

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

    Returns

    IteratorResult<ModelTreeWalkerValue>