浏览代码

Removing partial mention post-fixer now detects inserting text nodes inside a mention.

Maciej Gołaszewski 6 年之前
父节点
当前提交
ac95e46a1e
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 5 0
      packages/ckeditor5-mention/src/mentionediting.js
  2. 12 0
      packages/ckeditor5-mention/tests/mentionediting.js

+ 5 - 0
packages/ckeditor5-mention/src/mentionediting.js

@@ -158,6 +158,11 @@ function removePartialMentionPostFixer( writer, doc, schema ) {
 			// Check textNode where the change occurred.
 			if ( change.type == 'insert' || change.type == 'remove' ) {
 				checkAndFix( position.textNode );
+
+				// Occurs on pasting inside text node with mention;
+				const nodeAfterInsertedTextNode = position.textNode && position.textNode.nextSibling;
+				checkAndFix( nodeAfterInsertedTextNode );
+				checkAndFix( position.nodeBefore );
 			}
 
 			// Additional check: when removing text on mention boundaries.

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

@@ -286,6 +286,18 @@ describe( 'MentionEditing', () => {
 			expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span>bar</p>' );
 		} );
 
+		it( 'should remove mention on inserting text node inside a mention', () => {
+			editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
+
+			const paragraph = doc.getRoot().getChild( 0 );
+
+			model.change( writer => {
+				writer.insertText( 'baz', paragraph, 7 );
+			} );
+
+			expect( editor.getData() ).to.equal( '<p>foo @Jobazhn bar</p>' );
+		} );
+
 		it( 'should remove mention on inserting inline element inside a mention', () => {
 			model.schema.register( 'inline', {
 				allowWhere: '$text',