TreeWalker (engine/model)
@ckeditor/ckeditor5-engine/src/model/treewalker
Position iterator class. It allows to iterate forward and backward over the document.
Filtering
Properties
-
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.
-
Walking direction. Defaults
'forward'
. -
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
eachElement
will be returned once, while if the option isfalse
they might be returned twice: for'elementStart'
and'elementEnd'
. -
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. -
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. -
Flag indicating whether all consecutive characters with the same attributes should be returned as one
TextProxy
(true
) or one by one (false
). -
private
_boundaryEndParent : null | Element | DocumentFragment
module:engine/model/treewalker~TreeWalker#_boundaryEndParent
End boundary cached for optimization purposes.
-
private
_boundaryStartParent : null | Element | DocumentFragment
module:engine/model/treewalker~TreeWalker#_boundaryStartParent
Start boundary cached for optimization purposes.
-
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. -
private
_visitedParent : Element | DocumentFragment
module:engine/model/treewalker~TreeWalker#_visitedParent
Parent of the most recently visited node. Cached for optimization purposes.
Methods
-
constructor( options )
module:engine/model/treewalker~TreeWalker#constructor
Creates a range iterator. All parameters are optional, but you have to specify either
boundaries
orstartPosition
.Parameters
options : TreeWalkerOptions
Object with configuration.
-
Symbol.iterator() → IterableIterator<TreeWalkerValue>
module:engine/model/treewalker~TreeWalker#Symbol.iterator
-
next() → IteratorResult<TreeWalkerValue, any>
module:engine/model/treewalker~TreeWalker#next
-
skip( skip ) → void
module:engine/model/treewalker~TreeWalker#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 : ( TreeWalkerValue ) => boolean
Callback function. Gets
TreeWalkerValue
and should returntrue
if the value should be skipped orfalse
if not.
Returns
void
-
private
_next() → IteratorResult<TreeWalkerValue, any>
module:engine/model/treewalker~TreeWalker#_next
Makes a step forward in model. Moves the
position
to the next position and returns the encountered value.Returns
IteratorResult<TreeWalkerValue, any>
-
private
_previous() → IteratorResult<TreeWalkerValue, any>
module:engine/model/treewalker~TreeWalker#_previous
Makes a step backward in model. Moves the
position
to the previous position and returns the encountered value.Returns
IteratorResult<TreeWalkerValue, any>
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.