浏览代码

Fixed last test for `DocumentSelection`.

Maciej Bukowski 8 年之前
父节点
当前提交
ef5c9e6554

+ 5 - 2
packages/ckeditor5-engine/src/dev-utils/model.js

@@ -19,6 +19,7 @@ import ModelPosition from '../model/position';
 import ModelConversionDispatcher from '../conversion/modelconversiondispatcher';
 import ModelSelection from '../model/selection';
 import ModelDocumentFragment from '../model/documentfragment';
+import DocumentSelection from '../model/documentselection';
 
 import ViewConversionDispatcher from '../conversion/viewconversiondispatcher';
 import ViewSelection from '../view/selection';
@@ -46,7 +47,7 @@ import isPlainObject from '@ckeditor/ckeditor5-utils/src/lib/lodash/isPlainObjec
  * @param {Object} [options]
  * @param {Boolean} [options.withoutSelection=false] Whether to write the selection. When set to `true` selection will
  * be not included in returned string.
- * @param {Boolean} [options.rootName='main'] Name of the root from which data should be stringified. If not provided
+ * @param {String} [options.rootName='main'] Name of the root from which data should be stringified. If not provided
  * default `main` name will be used.
  * @returns {String} The stringified data.
  */
@@ -180,6 +181,8 @@ export function stringify( node, selectionOrPositionOrRange = null ) {
 	// Get selection from passed selection or position or range if at least one is specified.
 	if ( selectionOrPositionOrRange instanceof ModelSelection ) {
 		selection = selectionOrPositionOrRange;
+	} else if ( selectionOrPositionOrRange instanceof DocumentSelection ) {
+		selection = selectionOrPositionOrRange;
 	} else if ( selectionOrPositionOrRange instanceof ModelRange ) {
 		selection = new ModelSelection();
 		selection.addRange( selectionOrPositionOrRange );
@@ -211,7 +214,7 @@ export function stringify( node, selectionOrPositionOrRange = null ) {
 	modelToView.on( 'selection', convertRangeSelection() );
 	modelToView.on( 'selection', convertCollapsedSelection() );
 
-	// Convert model to view.
+	// Convert model to view.w
 	modelToView.convertInsert( range );
 
 	// Convert model selection to view selection.

+ 21 - 17
packages/ckeditor5-engine/src/model/documentselection.js

@@ -69,6 +69,18 @@ export default class DocumentSelection {
 		return this._selection.getLastRange();
 	}
 
+	getSelectedBlocks() {
+		return this._selection.getSelectedBlocks();
+	}
+
+	containsEntireContent( element ) {
+		return this._selection.containsEntireContent( element );
+	}
+
+	getLastPosition() {
+		return this._selection.getLastPosition();
+	}
+
 	_moveFocusTo( itemOrPosition, offset ) {
 		this._selection.moveFocusTo( itemOrPosition, offset );
 	}
@@ -77,14 +89,14 @@ export default class DocumentSelection {
 		this._selection.setTo( selectable, backwardSelectionOrOffset );
 	}
 
-	_setAttribute( key, value ) {
-		this._selection.setAttribute( key, value );
-	}
-
 	destroy() {
 		this._selection.destroy();
 	}
 
+	getAttributeKeys() {
+		return this._selection.getAttributeKeys();
+	}
+
 	getAttributes() {
 		return this._selection.getAttributes();
 	}
@@ -97,16 +109,12 @@ export default class DocumentSelection {
 		return this._selection.hasAttribute( key );
 	}
 
-	getSelectedBlocks() {
-		return this._selection.getSelectedBlocks();
-	}
-
-	containsEntireContent( element ) {
-		return this._selection.containsEntireContent( element );
+	_setAttribute( key, value ) {
+		this._selection.setAttribute( key, value );
 	}
 
-	getLastPosition() {
-		return this._selection.getLastPosition();
+	_removeAttribute( key ) {
+		this._selection.removeAttribute( key );
 	}
 
 	_clearAttributes() {
@@ -117,10 +125,6 @@ export default class DocumentSelection {
 		this._selection.removeAllRanges();
 	}
 
-	_removeAttribute( param ) {
-		this._selection.removeAttribute( param );
-	}
-
 	_getStoredAttributes() {
 		return this._selection._getStoredAttributes();
 	}
@@ -144,7 +148,7 @@ export default class DocumentSelection {
 	 * Checks whether the given attribute key is an attribute stored on an element.
 	 *
 	 * @protected
-	 * @param {String} key
+	 * @param {String} storePrefix
 	 * @returns {Boolean}
 	 */
 	static _isStoreAttributeKey( storePrefix ) {

+ 1 - 11
packages/ckeditor5-engine/src/model/liveselection.js

@@ -8,7 +8,6 @@
  */
 
 import Position from './position';
-import Range from './range';
 import LiveRange from './liverange';
 import Text from './text';
 import TextProxy from './textproxy';
@@ -291,14 +290,7 @@ export default class LiveSelection extends Selection {
 	 * @param {module:engine/model/range~Range} range
 	 */
 	_prepareRange( range ) {
-		if ( !( range instanceof Range ) ) {
-			/**
-			 * Trying to add an object that is not an instance of Range.
-			 *
-			 * @error model-selection-added-not-range
-			 */
-			throw new CKEditorError( 'model-selection-added-not-range: Trying to add an object that is not an instance of Range.' );
-		}
+		this._checkRange( range );
 
 		if ( range.root == this._document.graveyard ) {
 			/**
@@ -311,8 +303,6 @@ export default class LiveSelection extends Selection {
 			return;
 		}
 
-		this._checkRange( range );
-
 		const liveRange = LiveRange.createFromRange( range );
 
 		liveRange.on( 'change:range', ( evt, oldRange, data ) => {

+ 9 - 4
packages/ckeditor5-engine/src/model/selection.js

@@ -746,10 +746,6 @@ export default class Selection {
 	 * @param {module:engine/model/range~Range} range Range to add.
 	 */
 	_pushRange( range ) {
-		if ( !( range instanceof Range ) ) {
-			throw new CKEditorError( 'model-selection-added-not-range: Trying to add an object that is not an instance of Range.' );
-		}
-
 		this._checkRange( range );
 		this._ranges.push( Range.createFromRange( range ) );
 	}
@@ -761,6 +757,15 @@ export default class Selection {
 	 * @param {module:engine/model/range~Range} range Range to check.
 	 */
 	_checkRange( range ) {
+		if ( !( range instanceof Range ) ) {
+			/**
+			 * Trying to add an object that is not an instance of Range.
+			 *
+			 * @error model-selection-added-not-range
+			 */
+			throw new CKEditorError( 'model-selection-added-not-range: Trying to add an object that is not an instance of Range.' );
+		}
+
 		for ( let i = 0; i < this._ranges.length; i++ ) {
 			if ( range.isIntersecting( this._ranges[ i ] ) ) {
 				/**