TreeWalker (engine/view)
@ckeditor/ckeditor5-engine/src/view/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 set totrue
, walker will not return a parent node of the start position. EachElement
will be returned once. When set tofalse
each element might be returned twice: for'elementStart'
and'elementEnd'
. -
Iterator 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. -
private readonly
_boundaryEndParent : null | Node | DocumentFragment
module:engine/view/treewalker~TreeWalker#_boundaryEndParent
End boundary parent.
-
private readonly
_boundaryStartParent : null | Node | DocumentFragment
module:engine/view/treewalker~TreeWalker#_boundaryStartParent
Start boundary parent.
-
Iterator 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.
Methods
-
constructor( options )
module:engine/view/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.
Defaults to
{}
-
Symbol.iterator() → IterableIterator<TreeWalkerValue>
module:engine/view/treewalker~TreeWalker#Symbol.iterator
-
next() → IteratorResult<TreeWalkerValue, undefined>
module:engine/view/treewalker~TreeWalker#next
Gets the next tree walker's value.
Returns
IteratorResult<TreeWalkerValue, undefined>
Object implementing iterator interface, returning information about taken step.
-
skip( skip ) → void
module:engine/view/treewalker~TreeWalker#skip
Moves
position
in thedirection
skipping values as long as the callback function returnstrue
.For example:
walker.skip( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p> walker.skip( value => true ); // Move the position to the end: <p>{}foo</p> -> <p>foo</p>[] walker.skip( value => 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
_formatReturnValue( type, item, previousPosition, nextPosition, [ length ] ) → IteratorYieldResult<TreeWalkerValue>
module:engine/view/treewalker~TreeWalker#_formatReturnValue
Format returned data and adjust
previousPosition
andnextPosition
if reach the bound of theText
.Parameters
type : TreeWalkerValueType
Type of step.
item : Item
Item between old and new position.
previousPosition : Position
Previous position of iterator.
nextPosition : Position
Next position of iterator.
[ length ] : number
Length of the item.
Returns
IteratorYieldResult<TreeWalkerValue>
-
private
_next() → IteratorResult<TreeWalkerValue, undefined>
module:engine/view/treewalker~TreeWalker#_next
Makes a step forward in view. Moves the
position
to the next position and returns the encountered value.Returns
IteratorResult<TreeWalkerValue, undefined>
-
private
_previous() → IteratorResult<TreeWalkerValue, undefined>
module:engine/view/treewalker~TreeWalker#_previous
Makes a step backward in view. Moves the
position
to the previous position and returns the encountered value.Returns
IteratorResult<TreeWalkerValue, undefined>
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.