ModelTreeWalker
Position iterator class. It allows to iterate forward and backward over the document.
Properties
-
boundaries : null | ModelRange
readonlymodule:engine/model/treewalker~ModelTreeWalker#boundaries
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.
-
direction : ModelTreeWalkerDirection
readonlymodule:engine/model/treewalker~ModelTreeWalker#direction
Walking direction. Defaults
'forward'
. -
ignoreElementEnd : boolean
readonlymodule:engine/model/treewalker~ModelTreeWalker#ignoreElementEnd
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 istrue
eachModelElement
will be returned once, while if the option isfalse
they might be returned twice: for'elementStart'
and'elementEnd'
. -
position : ModelPosition
readonlymodule:engine/model/treewalker~ModelTreeWalker#position
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. -
shallow : boolean
readonlymodule:engine/model/treewalker~ModelTreeWalker#shallow
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. -
singleCharacters : boolean
readonlymodule:engine/model/treewalker~ModelTreeWalker#singleCharacters
Flag indicating whether all consecutive characters with the same attributes should be returned as one
ModelTextProxy
(true
) or one by one (false
). -
_boundaryEndParent : null | ModelElement | ModelDocumentFragment
privatemodule:engine/model/treewalker~ModelTreeWalker#_boundaryEndParent
End boundary cached for optimization purposes.
-
_boundaryStartParent : null | ModelElement | ModelDocumentFragment
privatemodule:engine/model/treewalker~ModelTreeWalker#_boundaryStartParent
Start boundary cached for optimization purposes.
-
_position : ModelPosition
privatemodule:engine/model/treewalker~ModelTreeWalker#_position
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. -
_visitedParent : ModelElement | ModelDocumentFragment
privatemodule:engine/model/treewalker~ModelTreeWalker#_visitedParent
Parent of the most recently visited node. Cached for optimization purposes.
Methods
-
constructor( options )
module:engine/model/treewalker~ModelTreeWalker#constructor
Creates a range iterator. All parameters are optional, but you have to specify either
boundaries
orstartPosition
.Parameters
options : ModelTreeWalkerOptions
Object with configuration.
-
Symbol.iterator() → IterableIterator<ModelTreeWalkerValue>
module:engine/model/treewalker~ModelTreeWalker#Symbol.iterator
-
jumpTo( position ) → void
module:engine/model/treewalker~ModelTreeWalker#jumpTo
Moves tree walker
position
to 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 usejumpTo
rather 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 : ModelPosition
Position to jump to.
Returns
void
-
next() → IteratorResult<ModelTreeWalkerValue>
module:engine/model/treewalker~ModelTreeWalker#next
-
skip( skip ) → void
module:engine/model/treewalker~ModelTreeWalker#skip
Moves
position
in thedirection
skipping 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.
Parameters
skip : ( value: ModelTreeWalkerValue ) => boolean
Callback function. Gets
ModelTreeWalkerValue
and should returntrue
if the value should be skipped orfalse
if not.
Returns
void
-
_next() → IteratorResult<ModelTreeWalkerValue>
privatemodule:engine/model/treewalker~ModelTreeWalker#_next
Makes a step forward in model. Moves the
position
to the next position and returns the encountered value.Returns
IteratorResult<ModelTreeWalkerValue>
-
_previous() → IteratorResult<ModelTreeWalkerValue>
privatemodule:engine/model/treewalker~ModelTreeWalker#_previous
Makes a step backward in model. Moves the
position
to the previous position and returns the encountered value.Returns
IteratorResult<ModelTreeWalkerValue>