8
0
Просмотр исходного кода

The findOptimalInsertionPosition() function should treat inline elements as text.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
5d0ebed6e2
2 измененных файлов с 23 добавлено и 2 удалено
  1. 1 1
      packages/ckeditor5-widget/src/utils.js
  2. 22 1
      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 ) {
+	if ( selectedElement && !model.schema.isInline( selectedElement ) ) {
 		return model.createPositionAfter( selectedElement );
 	}
 

+ 22 - 1
packages/ckeditor5-widget/tests/utils.js

@@ -392,7 +392,7 @@ describe( 'widget utils', () => {
 			expect( pos.path ).to.deep.equal( [ 1 ] );
 		} );
 
-		it( 'returns position before block if in the middle of that block', () => {
+		it( 'returns position before block if in the middle of that block (collapsed selection)', () => {
 			setData( model, '<paragraph>x</paragraph><paragraph>f[]oo</paragraph><paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection, model );
@@ -400,6 +400,14 @@ describe( 'widget utils', () => {
 			expect( pos.path ).to.deep.equal( [ 1 ] );
 		} );
 
+		it( 'returns position before block if in the middle of that block (non-collapsed selection)', () => {
+			setData( model, '<paragraph>x</paragraph><paragraph>f[o]o</paragraph><paragraph>y</paragraph>' );
+
+			const pos = findOptimalInsertionPosition( doc.selection, model );
+
+			expect( pos.path ).to.deep.equal( [ 1 ] );
+		} );
+
 		it( 'returns position after block if at the end of that block', () => {
 			setData( model, '<paragraph>x</paragraph><paragraph>foo[]</paragraph><paragraph>y</paragraph>' );
 
@@ -425,5 +433,18 @@ 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 ] );
+		} );
 	} );
 } );