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 elementEndtags. If the option is true walker will not return a parent node of the start position. If this option istrueeachElementwill be returned once, while if the option isfalsethey 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 elementEndtag.
- 
                        
                        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 | DocumentFragmentmodule:engine/model/treewalker~TreeWalker#_boundaryEndParentEnd boundary cached for optimization purposes. 
- 
                        private _boundaryStartParent : null | Element | DocumentFragmentmodule:engine/model/treewalker~TreeWalker#_boundaryStartParentStart 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 | DocumentFragmentmodule:engine/model/treewalker~TreeWalker#_visitedParentParent of the most recently visited node. Cached for optimization purposes. 
Methods
- 
                        constructor( options )module:engine/model/treewalker~TreeWalker#constructorCreates a range iterator. All parameters are optional, but you have to specify either boundariesorstartPosition.Parameters- options : TreeWalkerOptions
- Object with configuration. 
 
- 
                        Symbol.iterator() → IterableIterator<TreeWalkerValue>module:engine/model/treewalker~TreeWalker#Symbol.iterator
- 
                        jumpTo( position ) → voidmodule:engine/model/treewalker~TreeWalker#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 : Position
- Position to jump to. 
 Returns- void
 
- 
                        next() → IteratorResult<TreeWalkerValue>module:engine/model/treewalker~TreeWalker#next
- 
                        skip( skip ) → voidmodule:engine/model/treewalker~TreeWalker#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.Parameters- skip : ( value: TreeWalkerValue ) => boolean
- Callback function. Gets - TreeWalkerValueand should return- trueif the value should be skipped or- falseif not.
 Returns- void
 
- 
                        
                        Makes a step forward in model. Moves the positionto the next position and returns the encountered value.Returns- IteratorResult<TreeWalkerValue>
 
- 
                        private _previous() → IteratorResult<TreeWalkerValue>module:engine/model/treewalker~TreeWalker#_previousMakes a step backward in model. Moves the positionto the previous position and returns the encountered value.Returns- IteratorResult<TreeWalkerValue>
 
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.