|
@@ -20,6 +20,7 @@ export default class TreeWalker {
|
|
|
/**
|
|
/**
|
|
|
* Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
* Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @constructor
|
|
|
* @param {Object} options Object with configuration.
|
|
* @param {Object} options Object with configuration.
|
|
|
* @param {engine.model.Position} [options.startPosition] Starting position.
|
|
* @param {engine.model.Position} [options.startPosition] Starting position.
|
|
|
* @param {engine.model.Range} [options.boundaries=null] Range to define boundaries of the iterator.
|
|
* @param {engine.model.Range} [options.boundaries=null] Range to define boundaries of the iterator.
|
|
@@ -34,7 +35,6 @@ export default class TreeWalker {
|
|
|
* tags. If the option is true walker will not return a parent node of start position. If this option is `true`
|
|
* tags. If the option is true walker will not return a parent node of start position. If this option is `true`
|
|
|
* each {@link engine.model.Element} will be returned once, while if the option is `false` they might be returned
|
|
* each {@link engine.model.Element} will be returned once, while if the option is `false` they might be returned
|
|
|
* twice: for `'ELEMENT_START'` and `'ELEMENT_END'`.
|
|
* twice: for `'ELEMENT_START'` and `'ELEMENT_END'`.
|
|
|
- * @constructor
|
|
|
|
|
*/
|
|
*/
|
|
|
constructor(
|
|
constructor(
|
|
|
{
|
|
{
|
|
@@ -70,30 +70,16 @@ export default class TreeWalker {
|
|
|
*
|
|
*
|
|
|
* If boundaries are not defined they are set before first and after last child of the root node.
|
|
* If boundaries are not defined they are set before first and after last child of the root node.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @readonly
|
|
|
* @member {engine.model.Range} engine.model.TreeWalker#boundaries
|
|
* @member {engine.model.Range} engine.model.TreeWalker#boundaries
|
|
|
*/
|
|
*/
|
|
|
this.boundaries = boundaries;
|
|
this.boundaries = boundaries;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Start boundary cached for optimization purposes.
|
|
|
|
|
- *
|
|
|
|
|
- * @private
|
|
|
|
|
- * @member {engine.model.Element} engine.model.TreeWalker#_boundaryStartParent
|
|
|
|
|
- */
|
|
|
|
|
- this._boundaryStartParent = this.boundaries ? this.boundaries.start.parent : null;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * End boundary cached for optimization purposes.
|
|
|
|
|
- *
|
|
|
|
|
- * @private
|
|
|
|
|
- * @member {engine.model.Element} engine.model.TreeWalker#_boundaryEndParent
|
|
|
|
|
- */
|
|
|
|
|
- this._boundaryEndParent = this.boundaries ? this.boundaries.end.parent : null;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Iterator position. This is always static position, even if the initial position was a
|
|
* Iterator position. This is always static position, even if the initial position was a
|
|
|
* {@link engine.model.LivePosition live position}.
|
|
* {@link engine.model.LivePosition live position}.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @readonly
|
|
|
* @member {engine.model.Position} engine.model.TreeWalker#position
|
|
* @member {engine.model.Position} engine.model.TreeWalker#position
|
|
|
*/
|
|
*/
|
|
|
if ( startPosition ) {
|
|
if ( startPosition ) {
|
|
@@ -105,8 +91,8 @@ export default class TreeWalker {
|
|
|
/**
|
|
/**
|
|
|
* Walking direction. Defaults `FORWARD`.
|
|
* Walking direction. Defaults `FORWARD`.
|
|
|
*
|
|
*
|
|
|
- * @member engine.model.TreeWalker#direction
|
|
|
|
|
- * @type {'BACKWARD'|'FORWARD'} core.model.TreeWalkerDirection
|
|
|
|
|
|
|
+ * @readonly
|
|
|
|
|
+ * @member {'BACKWARD'|'FORWARD'} engine.model.TreeWalker#direction
|
|
|
*/
|
|
*/
|
|
|
this.direction = direction;
|
|
this.direction = direction;
|
|
|
|
|
|
|
@@ -114,6 +100,7 @@ export default class TreeWalker {
|
|
|
* Flag indicating whether all consecutive characters with the same attributes should be
|
|
* Flag indicating whether all consecutive characters with the same attributes should be
|
|
|
* returned as one {@link engine.model.CharacterProxy} (`true`) or one by one (`false`).
|
|
* returned as one {@link engine.model.CharacterProxy} (`true`) or one by one (`false`).
|
|
|
*
|
|
*
|
|
|
|
|
+ * @readonly
|
|
|
* @member {Boolean} engine.model.TreeWalker#singleCharacters
|
|
* @member {Boolean} engine.model.TreeWalker#singleCharacters
|
|
|
*/
|
|
*/
|
|
|
this.singleCharacters = !!singleCharacters;
|
|
this.singleCharacters = !!singleCharacters;
|
|
@@ -122,6 +109,7 @@ export default class TreeWalker {
|
|
|
* Flag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any
|
|
* 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 `ELEMENT_END` tag.
|
|
* iterated node will not be returned along with `ELEMENT_END` tag.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @readonly
|
|
|
* @member {Boolean} engine.model.TreeWalker#shallow
|
|
* @member {Boolean} engine.model.TreeWalker#shallow
|
|
|
*/
|
|
*/
|
|
|
this.shallow = !!shallow;
|
|
this.shallow = !!shallow;
|
|
@@ -132,10 +120,27 @@ export default class TreeWalker {
|
|
|
* be returned once, while if the option is `false` they might be returned twice:
|
|
* be returned once, while if the option is `false` they might be returned twice:
|
|
|
* for `'ELEMENT_START'` and `'ELEMENT_END'`.
|
|
* for `'ELEMENT_START'` and `'ELEMENT_END'`.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @readonly
|
|
|
* @member {Boolean} engine.model.TreeWalker#ignoreElementEnd
|
|
* @member {Boolean} engine.model.TreeWalker#ignoreElementEnd
|
|
|
*/
|
|
*/
|
|
|
this.ignoreElementEnd = !!ignoreElementEnd;
|
|
this.ignoreElementEnd = !!ignoreElementEnd;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Start boundary cached for optimization purposes.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @member {engine.model.Element} engine.model.TreeWalker#_boundaryStartParent
|
|
|
|
|
+ */
|
|
|
|
|
+ this._boundaryStartParent = this.boundaries ? this.boundaries.start.parent : null;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * End boundary cached for optimization purposes.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @private
|
|
|
|
|
+ * @member {engine.model.Element} engine.model.TreeWalker#_boundaryEndParent
|
|
|
|
|
+ */
|
|
|
|
|
+ this._boundaryEndParent = this.boundaries ? this.boundaries.end.parent : null;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Parent of the most recently visited node. Cached for optimization purposes.
|
|
* Parent of the most recently visited node. Cached for optimization purposes.
|
|
|
*
|
|
*
|
|
@@ -157,7 +162,7 @@ export default class TreeWalker {
|
|
|
* Detects walking direction and makes step forward or backward.
|
|
* Detects walking direction and makes step forward or backward.
|
|
|
*
|
|
*
|
|
|
* @returns {Object} Object implementing iterator interface, returning information about taken step.
|
|
* @returns {Object} Object implementing iterator interface, returning information about taken step.
|
|
|
- */
|
|
|
|
|
|
|
+ */
|
|
|
next() {
|
|
next() {
|
|
|
if ( this.direction == 'FORWARD' ) {
|
|
if ( this.direction == 'FORWARD' ) {
|
|
|
return this._next();
|
|
return this._next();
|
|
@@ -175,6 +180,7 @@ export default class TreeWalker {
|
|
|
* Makes a step forward in model. Moves the {@link #position} to the next position and returns the encountered value.
|
|
* Makes a step forward in model. Moves the {@link #position} to the next position and returns the encountered value.
|
|
|
*
|
|
*
|
|
|
* @private
|
|
* @private
|
|
|
|
|
+ * @returns {Object}
|
|
|
* @returns {Boolean} return.done True if iterator is done.
|
|
* @returns {Boolean} return.done True if iterator is done.
|
|
|
* @returns {engine.model.TreeWalkerValue} return.value Information about taken step.
|
|
* @returns {engine.model.TreeWalkerValue} return.value Information about taken step.
|
|
|
*/
|
|
*/
|
|
@@ -248,6 +254,7 @@ export default class TreeWalker {
|
|
|
* Makes a step backward in model. Moves the {@link #position} to the previous position and returns the encountered value.
|
|
* Makes a step backward in model. Moves the {@link #position} to the previous position and returns the encountered value.
|
|
|
*
|
|
*
|
|
|
* @private
|
|
* @private
|
|
|
|
|
+ * @returns {Object}
|
|
|
* @returns {Boolean} return.done True if iterator is done.
|
|
* @returns {Boolean} return.done True if iterator is done.
|
|
|
* @returns {core.model.TreeWalkerValue} return.value Information about taken step.
|
|
* @returns {core.model.TreeWalkerValue} return.value Information about taken step.
|
|
|
*/
|
|
*/
|