Browse Source

Minor logic clarification.

Piotrek Koszuliński 6 years ago
parent
commit
7371dfb726
2 changed files with 17 additions and 15 deletions
  1. 1 1
      packages/ckeditor5-widget/src/utils.js
  2. 16 14
      packages/ckeditor5-widget/tests/utils.js

+ 1 - 1
packages/ckeditor5-widget/src/utils.js

@@ -265,7 +265,7 @@ export function toWidgetEditable( editable, writer ) {
 export function findOptimalInsertionPosition( selection, model ) {
 	const selectedElement = selection.getSelectedElement();
 
-	if ( selectedElement && !model.schema.isInline( selectedElement ) ) {
+	if ( selectedElement && model.schema.isBlock( selectedElement ) ) {
 		return model.createPositionAfter( selectedElement );
 	}
 

+ 16 - 14
packages/ckeditor5-widget/tests/utils.js

@@ -361,7 +361,8 @@ describe( 'widget utils', () => {
 
 			model.schema.extend( 'image', {
 				allowIn: '$root',
-				isObject: true
+				isObject: true,
+				isBlock: true
 			} );
 
 			model.schema.extend( 'span', { allowIn: 'paragraph' } );
@@ -376,6 +377,20 @@ describe( 'widget utils', () => {
 			expect( pos.path ).to.deep.equal( [ 2 ] );
 		} );
 
+		it( 'returns position before parent block if an inline object is selected', () => {
+			model.schema.register( 'placeholder', {
+				allowWhere: '$text',
+				isInline: true,
+				isObject: true
+			} );
+
+			setData( model, '<paragraph>x</paragraph><paragraph>f[<placeholder></placeholder>]oo</paragraph><paragraph>y</paragraph>' );
+
+			const pos = findOptimalInsertionPosition( doc.selection, model );
+
+			expect( pos.path ).to.deep.equal( [ 1 ] );
+		} );
+
 		it( 'returns position inside empty block', () => {
 			setData( model, '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>y</paragraph>' );
 
@@ -433,18 +448,5 @@ describe( 'widget utils', () => {
 
 			expect( pos.path ).to.deep.equal( [ 3 ] );
 		} );
-
-		it( 'returns position before block selection is on inline element', () => {
-			model.schema.register( 'placeholder', {
-				allowWhere: '$text',
-				isInline: true
-			} );
-
-			setData( model, '<paragraph>x</paragraph><paragraph>f[<placeholder></placeholder>]oo</paragraph><paragraph>y</paragraph>' );
-
-			const pos = findOptimalInsertionPosition( doc.selection, model );
-
-			expect( pos.path ).to.deep.equal( [ 1 ] );
-		} );
 	} );
 } );