浏览代码

Increased CC of ViewConversionDispatcher.

Oskar Wróbel 7 年之前
父节点
当前提交
c0c2796b79

+ 6 - 6
packages/ckeditor5-engine/src/conversion/viewconversiondispatcher.js

@@ -273,23 +273,23 @@ export default class ViewConversionDispatcher {
 	 */
 	_splitToAllowedParent( element, cursorPosition ) {
 		// Try to find allowed parent.
-		const allowedParent = this.conversionApi.schema.findAllowedParent( element, cursorPosition, this._modelCursor.parent );
+		const allowedParent = this.conversionApi.schema.findAllowedParent( element, cursorPosition );
 
 		// When there is no parent that allows to insert element then return `null`.
 		if ( !allowedParent ) {
 			return null;
 		}
 
-		// When allowed parent is in context tree.
-		if ( this._modelCursor.parent.getAncestors().includes( allowedParent ) ) {
-			return null;
-		}
-
 		// When current position parent allows to insert element then return this position.
 		if ( allowedParent === cursorPosition.parent ) {
 			return { position: cursorPosition };
 		}
 
+		// When allowed parent is in context tree.
+		if ( this._modelCursor.parent.getAncestors().includes( allowedParent ) ) {
+			return null;
+		}
+
 		// Split element to allowed parent.
 		const splitResult = this.conversionApi.writer.split( cursorPosition, allowedParent );
 

+ 19 - 0
packages/ckeditor5-engine/tests/conversion/viewconversiondispatcher.js

@@ -606,6 +606,25 @@ describe( 'ViewConversionDispatcher', () => {
 				dispatcher.convert( new ViewDocumentFragment() );
 				sinon.assert.calledOnce( spy );
 			} );
+
+			it( 'should return null if element is not allowed in position and any of ancestors but is allowed in context tree', () => {
+				const spy = sinon.spy();
+
+				model.schema.register( 'div', {
+					allowIn: '$root',
+				} );
+
+				dispatcher.on( 'documentFragment', ( evt, data, conversionApi ) => {
+					const code = conversionApi.writer.createElement( 'div' );
+					const result = conversionApi.splitToAllowedParent( code, data.cursorPosition );
+
+					expect( result ).to.null;
+					spy();
+				} );
+
+				dispatcher.convert( new ViewDocumentFragment(), [ '$root', 'paragraph' ] );
+				sinon.assert.calledOnce( spy );
+			} );
 		} );
 	} );
 } );