瀏覽代碼

Add deep check of inserted item in the search of a broken mention.

Maciej Gołaszewski 6 年之前
父節點
當前提交
1760ec4677
共有 2 個文件被更改,包括 22 次插入4 次删除
  1. 4 4
      packages/ckeditor5-mention/src/mentionediting.js
  2. 18 0
      packages/ckeditor5-mention/tests/mentionediting.js

+ 4 - 4
packages/ckeditor5-mention/src/mentionediting.js

@@ -163,11 +163,11 @@ function removePartialMentionPostFixer( writer, doc, schema ) {
 		}
 
 		// Check text nodes in inserted elements (might occur when splitting paragraph or pasting content inside text with mention).
-		if ( change.name != '$text' && change.type == 'insert' && schema.checkChild( change.name, '$text' ) ) {
+		if ( change.name != '$text' && change.type == 'insert' ) {
 			const insertedNode = position.nodeAfter;
 
-			for ( const child of insertedNode.getChildren() ) {
-				wasChanged = checkAndFix( child, writer ) || wasChanged;
+			for ( const { item } of writer.createRangeIn( insertedNode ).getWalker() ) {
+				wasChanged = checkAndFix( item, writer ) || wasChanged;
 			}
 		}
 
@@ -219,7 +219,7 @@ function extendAttributeOnMentionPostFixer( writer, doc ) {
 // @param {module:engine/model/node~Node} node a node to check
 // @returns {Boolean}
 function isBrokenMentionNode( node ) {
-	if ( !node || !node.is( 'text' ) || !node.hasAttribute( 'mention' ) ) {
+	if ( !node || !( node.is( 'text' ) || node.is( 'textProxy' ) ) || !node.hasAttribute( 'mention' ) ) {
 		return false;
 	}
 

+ 18 - 0
packages/ckeditor5-mention/tests/mentionediting.js

@@ -348,6 +348,24 @@ describe( 'MentionEditing', () => {
 
 			expect( editor.getData() ).to.equal( '<p>foo @Jo</p><p>hn bar</p>' );
 		} );
+
+		it( 'should remove mention when deep splitting elements', () => {
+			model.schema.register( 'blockQuote', {
+				allowWhere: '$block',
+				allowContentOf: '$root'
+			} );
+
+			editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
+			editor.setData( '<blockquote><p>foo <span class="mention" data-mention="John">@John</span> bar</p></blockquote>' );
+
+			model.change( writer => {
+				const paragraph = doc.getRoot().getChild( 0 ).getChild( 0 );
+
+				writer.split( writer.createPositionAt( paragraph, 7 ), doc.getRoot() );
+			} );
+
+			expect( editor.getData() ).to.equal( '<blockquote><p>foo @Jo</p></blockquote><blockquote><p>hn bar</p></blockquote>' );
+		} );
 	} );
 
 	describe( 'extend attribute on mention post-fixer', () => {