Browse Source

Added missing view selection test.

Maciej Bukowski 8 years ago
parent
commit
3ee3adc9c5
1 changed files with 29 additions and 31 deletions
  1. 29 31
      packages/ckeditor5-engine/src/view/selection.js

+ 29 - 31
packages/ckeditor5-engine/src/view/selection.js

@@ -195,32 +195,6 @@ export default class Selection {
 		return null;
 	}
 
-	/**
-	 * Adds a range to the selection. Added range is copied. This means that passed range is not saved in the
-	 * selection instance and you can safely operate on it.
-	 *
-	 * Accepts a flag describing in which way the selection is made - passed range might be selected from
-	 * {@link module:engine/view/range~Range#start start} to {@link module:engine/view/range~Range#end end}
-	 * or from {@link module:engine/view/range~Range#end end} to {@link module:engine/view/range~Range#start start}.
-	 * The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
-	 *
-	 * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
-	 * with ranges already stored in Selection instance.
-	 *
-	 * @fires change
-	 * @param {module:engine/view/range~Range} range
-	 * @param {Boolean} [isBackward]
-	 */
-	_addRange( range, isBackward = false ) {
-		if ( !( range instanceof Range ) ) {
-			throw new CKEditorError( 'view-selection-invalid-range: Invalid Range.' );
-		}
-
-		this._pushRange( range );
-		this._lastRangeBackward = !!isBackward;
-		this.fire( 'change' );
-	}
-
 	/**
 	 * Returns an iterable that contains copies of all ranges added to the selection.
 	 *
@@ -480,11 +454,7 @@ export default class Selection {
 		this._ranges = [];
 
 		for ( const range of newRanges ) {
-			if ( !( range instanceof Range ) ) {
-				throw new CKEditorError( 'view-selection-invalid-range: Invalid Range.' );
-			}
-
-			this._pushRange( range );
+			this._addRange( range );
 		}
 
 		this._lastRangeBackward = !!isLastBackward;
@@ -528,6 +498,8 @@ export default class Selection {
 		} else {
 			this._addRange( new Range( anchor, newFocus ) );
 		}
+
+		this.fire( 'change' );
 	}
 
 	/**
@@ -563,6 +535,32 @@ export default class Selection {
 		return selection;
 	}
 
+	/**
+	 * Adds a range to the selection. Added range is copied. This means that passed range is not saved in the
+	 * selection instance and you can safely operate on it.
+	 *
+	 * Accepts a flag describing in which way the selection is made - passed range might be selected from
+	 * {@link module:engine/view/range~Range#start start} to {@link module:engine/view/range~Range#end end}
+	 * or from {@link module:engine/view/range~Range#end end} to {@link module:engine/view/range~Range#start start}.
+	 * The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
+	 *
+	 * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
+	 * with ranges already stored in Selection instance.
+	 *
+	 * @private
+	 * @fires change
+	 * @param {module:engine/view/range~Range} range
+	 * @param {Boolean} [isBackward]
+	 */
+	_addRange( range, isBackward = false ) {
+		if ( !( range instanceof Range ) ) {
+			throw new CKEditorError( 'view-selection-invalid-range: Invalid Range.' );
+		}
+
+		this._pushRange( range );
+		this._lastRangeBackward = !!isBackward;
+	}
+
 	/**
 	 * Adds range to selection - creates copy of given range so it can be safely used and modified.
 	 *