Selaa lähdekoodia

Made the WidgetTypeAround plugin use the new InsertParagraphCommand API.

Aleksander Nowodzinski 5 vuotta sitten
vanhempi
commit
9ea4f7023e

+ 8 - 2
packages/ckeditor5-widget/src/widgettypearound/widgettypearound.js

@@ -109,10 +109,16 @@ export default class WidgetTypeAround extends Plugin {
 		const editor = this.editor;
 		const editingView = editor.editing.view;
 		const widgetModelElement = editor.editing.mapper.toModelElement( widgetViewElement );
+		let modelPosition;
+
+		if ( position === 'before' ) {
+			modelPosition = editor.model.createPositionBefore( widgetModelElement );
+		} else {
+			modelPosition = editor.model.createPositionAfter( widgetModelElement );
+		}
 
 		editor.execute( 'insertParagraph', {
-			element: widgetModelElement,
-			position
+			position: modelPosition
 		} );
 
 		editingView.focus();

+ 12 - 8
packages/ckeditor5-widget/tests/widgettypearound/widgettypearound.js

@@ -65,11 +65,13 @@ describe( 'WidgetTypeAround', () => {
 
 			plugin._insertParagraph( viewRoot.getChild( 0 ), 'before' );
 
+			const spyExecutePosition = executeSpy.firstCall.args[ 1 ].position;
+			const positionBeforeWidget = editor.model.createPositionBefore( editor.model.document.getRoot().getChild( 0 ) );
+
 			sinon.assert.calledOnce( executeSpy );
-			sinon.assert.calledWithExactly( executeSpy, 'insertParagraph', {
-				position: 'before',
-				element: editor.model.document.getRoot().getChild( 1 )
-			} );
+			sinon.assert.calledWith( executeSpy, 'insertParagraph' );
+
+			expect( spyExecutePosition.isEqual( positionBeforeWidget ) ).to.be.true;
 
 			expect( getModelData( editor.model ) ).to.equal( '<paragraph>[]</paragraph><blockWidget></blockWidget>' );
 		} );
@@ -79,11 +81,13 @@ describe( 'WidgetTypeAround', () => {
 
 			plugin._insertParagraph( viewRoot.getChild( 0 ), 'after' );
 
+			const spyExecutePosition = executeSpy.firstCall.args[ 1 ].position;
+			const positionAfterWidget = editor.model.createPositionAfter( editor.model.document.getRoot().getChild( 0 ) );
+
 			sinon.assert.calledOnce( executeSpy );
-			sinon.assert.calledWithExactly( executeSpy, 'insertParagraph', {
-				position: 'after',
-				element: editor.model.document.getRoot().getChild( 0 )
-			} );
+			sinon.assert.calledWith( executeSpy, 'insertParagraph' );
+
+			expect( spyExecutePosition.isEqual( positionAfterWidget ) ).to.be.true;
 
 			expect( getModelData( editor.model ) ).to.equal( '<blockWidget></blockWidget><paragraph>[]</paragraph>' );
 		} );