TreeWalker (engine/view)
@ckeditor/ckeditor5-engine/src/view/treewalker
Position iterator class. It allows to iterate forward and backward over the document.
Filtering
Properties
-
boundaries : Range
module:engine/view/treewalker~TreeWalker#boundaries
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.
-
direction : 'backward' | 'forward'
module:engine/view/treewalker~TreeWalker#direction
readonly
Walking direction. Defaults
'forward'
. -
ignoreElementEnd : Boolean
module:engine/view/treewalker~TreeWalker#ignoreElementEnd
readonly
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. -
shallow : Boolean
module:engine/view/treewalker~TreeWalker#shallow
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. -
singleCharacters : Boolean
module:engine/view/treewalker~TreeWalker#singleCharacters
readonly
-
_boundaryEndParent : Node
module:engine/view/treewalker~TreeWalker#_boundaryEndParent
private
End boundary parent.
-
_boundaryStartParent : Node
module:engine/view/treewalker~TreeWalker#_boundaryStartParent
private
Start boundary parent.
Methods
-
constructor( options = { [options.boundaries], [options.startPosition], [options.direction], [options.singleCharacters], [options.shallow], [options.ignoreElementEnd] } )
module:engine/view/treewalker~TreeWalker#constructor
Creates a range iterator. All parameters are optional, but you have to specify either
boundaries
orstartPosition
.Parameters
options : Object
Object with configuration.
Properties[ options.boundaries ] : Range
Range to define boundaries of the iterator.
[ options.startPosition ] : Position
Starting position.
[ options.direction ] : 'forward' | 'backward'
Walking direction.
Defaults to
'forward'
[ options.singleCharacters ] : Boolean
Flag indicating whether all characters from
Text
should be returned as oneText
(false
) ore one by one asTextProxy
(true
).Defaults to
false
[ options.shallow ] : Boolean
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.Defaults to
false
[ options.ignoreElementEnd ] : Boolean
Flag indicating whether iterator should ignore
elementEnd
tags. If the option is true walker will not return a parent node of 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'
.Defaults to
false
-
Symbol.iterator() → Iterable.<TreeWalkerValue>
module:engine/view/treewalker~TreeWalker#Symbol.iterator
Iterable interface.
Returns
Iterable.<TreeWalkerValue>
-
next() → TreeWalkerValue
module:engine/view/treewalker~TreeWalker#next
Gets the next tree walker's value.
Returns
TreeWalkerValue
Object implementing iterator interface, returning information about taken step.
-
skip( skip )
module:engine/view/treewalker~TreeWalker#skip
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 : function
Callback function. Gets
TreeWalkerValue
and should returntrue
if the value should be skipped orfalse
if not.
-
_formatReturnValue( type, item, previousPosition, nextPosition, [ length ] ) → TreeWalkerValue
module:engine/view/treewalker~TreeWalker#_formatReturnValue
private
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
-
_next() → Object
module:engine/view/treewalker~TreeWalker#_next
private
Makes a step forward in view. Moves the
position
to the next position and returns the encountered value.Returns
Object
Boolean
return.done
true
if iterator is done,false
otherwise.TreeWalkerValue
return.value Information about taken step.
-
_previous() → Object
module:engine/view/treewalker~TreeWalker#_previous
private
Makes a step backward in view. Moves the
position
to the previous position and returns the encountered value.Returns
Object
Boolean
return.done True if iterator is done.
TreeWalkerValue
return.value Information about taken step.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.