ModelTreeWalker
Position iterator class. It allows to iterate forward and backward over the document.
Properties
boundaries : null | ModelRangereadonlymodule:engine/model/treewalker~ModelTreeWalker#boundariesIterator 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.
direction : ModelTreeWalkerDirectionreadonlymodule:engine/model/treewalker~ModelTreeWalker#directionWalking direction. Defaults
'forward'.ignoreElementEnd : booleanreadonlymodule:engine/model/treewalker~ModelTreeWalker#ignoreElementEndFlag indicating whether iterator should ignore
elementEndtags. If the option is true walker will not return a parent node of the start position. If this option istrueeachModelElementwill be returned once, while if the option isfalsethey might be returned twice: for'elementStart'and'elementEnd'.position : ModelPositionreadonlymodule:engine/model/treewalker~ModelTreeWalker#positionIterator 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.shallow : booleanreadonlymodule:engine/model/treewalker~ModelTreeWalker#shallowFlag 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
elementEndtag.singleCharacters : booleanreadonlymodule:engine/model/treewalker~ModelTreeWalker#singleCharactersFlag indicating whether all consecutive characters with the same attributes should be returned as one
ModelTextProxy(true) or one by one (false)._boundaryEndParent : null | ModelElement | ModelDocumentFragmentprivatemodule:engine/model/treewalker~ModelTreeWalker#_boundaryEndParentEnd boundary cached for optimization purposes.
_boundaryStartParent : null | ModelElement | ModelDocumentFragmentprivatemodule:engine/model/treewalker~ModelTreeWalker#_boundaryStartParentStart boundary cached for optimization purposes.
_position : ModelPositionprivatemodule:engine/model/treewalker~ModelTreeWalker#_positionIterator 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._visitedParent : ModelElement | ModelDocumentFragmentprivatemodule:engine/model/treewalker~ModelTreeWalker#_visitedParentParent of the most recently visited node. Cached for optimization purposes.
Methods
constructor( options )module:engine/model/treewalker~ModelTreeWalker#constructorCreates a range iterator. All parameters are optional, but you have to specify either
boundariesorstartPosition.Parameters
options : ModelTreeWalkerOptionsObject with configuration.
Symbol.iterator() → IterableIterator<ModelTreeWalkerValue>module:engine/model/treewalker~ModelTreeWalker#Symbol.iteratorjumpTo( position ) → voidmodule:engine/model/treewalker~ModelTreeWalker#jumpToMoves tree walker
positionto providedposition. 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 usejumpTorather thanskip.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 : ModelPositionPosition to jump to.
Returns
void
next() → IteratorResult<ModelTreeWalkerValue>module:engine/model/treewalker~ModelTreeWalker#nextskip( skip ) → voidmodule:engine/model/treewalker~ModelTreeWalker#skipMoves
positionin thedirectionskipping values as long as the callback function returnstrue.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 codeParameters
skip : ( value: ModelTreeWalkerValue ) => booleanCallback function. Gets
ModelTreeWalkerValueand should returntrueif the value should be skipped orfalseif not.
Returns
void
_next() → IteratorResult<ModelTreeWalkerValue>privatemodule:engine/model/treewalker~ModelTreeWalker#_nextMakes a step forward in model. Moves the
positionto the next position and returns the encountered value.Returns
IteratorResult<ModelTreeWalkerValue>
_previous() → IteratorResult<ModelTreeWalkerValue>privatemodule:engine/model/treewalker~ModelTreeWalker#_previousMakes a step backward in model. Moves the
positionto the previous position and returns the encountered value.Returns
IteratorResult<ModelTreeWalkerValue>