Oskar Wrobel пре 9 година
родитељ
комит
f587876952

+ 9 - 10
packages/ckeditor5-engine/src/treemodel/composer/modifyselection.js

@@ -38,19 +38,18 @@ export default function modifySelection( selection, options = {} ) {
 		return;
 	}
 
-	// Replace TreeWalker step wrapper by clean step value.
-	next = next.value;
+	let value = next.value;
 
 	// 2. Consume next character.
-	if ( next.type == 'CHARACTER' ) {
-		selection.setFocus( next.nextPosition );
+	if ( value.type == 'CHARACTER' ) {
+		selection.setFocus( value.nextPosition );
 
 		return;
 	}
 
 	// 3. We're entering an element, so let's consume it fully.
-	if ( next.type == ( isForward ? 'ELEMENT_START' : 'ELEMENT_END' ) ) {
-		selection.setFocus( next.item, isForward ? 'AFTER' : 'BEFORE' );
+	if ( value.type == ( isForward ? 'ELEMENT_START' : 'ELEMENT_END' ) ) {
+		selection.setFocus( value.item, isForward ? 'AFTER' : 'BEFORE' );
 
 		return;
 	}
@@ -64,16 +63,16 @@ export default function modifySelection( selection, options = {} ) {
 	}
 
 	// Replace TreeWalker step wrapper by clean step value.
-	next = next.value;
+	value = next.value;
 
 	// 4.2. Character found after element end. Not really a valid case in our data model, but let's
 	// do something sensible and put the selection focus before that character.
-	if ( next.type == 'CHARACTER' ) {
-		selection.setFocus( next.previousPosition );
+	if ( value.type == 'CHARACTER' ) {
+		selection.setFocus( value.previousPosition );
 	}
 	// 4.3. OK, we're entering a new element. So let's place there the focus.
 	else {
-		selection.setFocus( next.item, isForward ? 0 : 'END' );
+		selection.setFocus( value.item, isForward ? 0 : 'END' );
 	}
 }
 

+ 16 - 18
packages/ckeditor5-engine/src/treemodel/treewalker.js

@@ -21,9 +21,9 @@ export default class TreeWalker {
 	 * Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
 	 *
 	 * @param {Object} options Object with configuration.
-	 * @param {engine.treeModel.Range} [options.boundaries] Range to define boundaries of the iterator.
+	 * @param {engine.treeModel.Range} [options.boundaries=null] Range to define boundaries of the iterator.
 	 * @param {engine.treeModel.Position} [options.startPosition] Starting position.
-	 * @param {'FORWARD'|'BACKWARD'} [options.direction] Walking direction.
+	 * @param {'FORWARD'|'BACKWARD'} [options.direction='FORWARD'] Walking direction.
 	 * @param {Boolean} [options.singleCharacters=false] Flag indicating whether all consecutive characters with the same attributes
 	 * should be returned one by one as multiple {@link engine.treeModel.CharacterProxy} (`true`) objects or as one
 	 * {@link engine.treeModel.TextProxy} (`false`).
@@ -37,7 +37,7 @@ export default class TreeWalker {
 	 */
 	constructor(
 		{
-			boundaries,
+			boundaries = null,
 			startPosition,
 			direction = 'FORWARD',
 			singleCharacters = false,
@@ -71,7 +71,7 @@ export default class TreeWalker {
 		 *
 		 * @member {engine.treeModel.Range} engine.treeModel.TreeWalker#boundaries
 		 */
-		this.boundaries = boundaries || null;
+		this.boundaries = boundaries;
 
 		/**
 		 * Start boundary cached for optimization purposes.
@@ -107,7 +107,7 @@ export default class TreeWalker {
 		 * @member engine.treeModel.TreeWalker#direction
 		 * @type {'BACKWARD'|'FORWARD'} core.treeModel.TreeWalkerDirection
 		 */
-		this.direction = direction || 'FORWARD';
+		this.direction = direction;
 
 		/**
 		 * Flag indicating whether all consecutive characters with the same attributes should be
@@ -347,20 +347,18 @@ function formatReturnValue( type, item, previousPosition, nextPosition, length )
  * @property {engine.treeModel.TreeWalkerValueType} type
  * @property {engine.treeModel.Item} item Item between old and new positions of {@link engine.treeModel.TreeWalker}.
  * @property {engine.treeModel.Position} previousPosition Previous position of the iterator.
- * 		Forward iteration:
- * 			For `'ELEMENT_END'` it is the last position inside the element. For all other types it is the position
- * 			before the item. Note that it is more efficient to use this position then calculate the position before
- * 			the node using {@link engine.treeModel.Position.createBefore}. It is also more efficient to get the
- * 			position after node by shifting `previousPosition` by `length`, using {@link engine.treeModel.Position#getShiftedBy},
- * 			then calculate the position using {@link engine.treeModel.Position.createAfter}.
- * 		Backward iteration:
- * 			For `'ELEMENT_START'` it is the first position inside the element. For all other types it is the position
- * 			after item.
+ * * Forward iteration: For `'ELEMENT_END'` it is the last position inside the element. For all other types it is the
+ * position before the item. Note that it is more efficient to use this position then calculate the position before
+ * the node using {@link engine.treeModel.Position.createBefore}. It is also more efficient to get the
+ * position after node by shifting `previousPosition` by `length`, using {@link engine.treeModel.Position#getShiftedBy},
+ * then calculate the position using {@link engine.treeModel.Position.createAfter}.
+ * * Backward iteration: For `'ELEMENT_START'` it is the first position inside the element. For all other types it is
+ * the position after item.
  * @property {engine.treeModel.Position} nextPosition Next position of the iterator.
- * 		Forward iteration:
- * 			For `'ELEMENT_START'` it is the first position inside the element. For all other types it is the position after the item.
- * 		Backward iteration:
- *			For `'ELEMENT_END'` it is last position inside element. For all other types it is the position before the item.
+ * * Forward iteration: For `'ELEMENT_START'` it is the first position inside the element. For all other types it is
+ * the position after the item.
+ * * Backward iteration: For `'ELEMENT_END'` it is last position inside element. For all other types it is the position
+ * before the item.
  * @property {Number} [length] Length of the item. For `'ELEMENT_START'` and `'CHARACTER'` it is 1. For `'TEXT'` it is
  * the length of the text. For `'ELEMENT_END'` it is undefined.
  */