Kaynağa Gözat

Add test for typing with selection attributes set.

Maciej Gołaszewski 6 yıl önce
ebeveyn
işleme
d2320871df

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

@@ -162,11 +162,7 @@ function removePartialMentionPostFixer( writer, doc, schema ) {
 			const nodeAfterInsertedTextNode = position.textNode && position.textNode.nextSibling;
 			checkAndFix( nodeAfterInsertedTextNode );
 			checkAndFix( position.nodeBefore );
-
-			// Additional check: when removing text at the beginning of a mention.
-			if ( change.type == 'remove' ) {
-				checkAndFix( position.nodeAfter );
-			}
+			checkAndFix( position.nodeAfter );
 		}
 
 		// Check text nodes on inserted elements (might occur when splitting paragraph on enter key).

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

@@ -217,6 +217,27 @@ describe( 'MentionEditing', () => {
 			expect( editor.getData() ).to.equal( '<p>foo @Jaohn bar</p>' );
 		} );
 
+		it( 'should remove mention on typing in mention node with selection attributes set', () => {
+			editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
+
+			const textNode = doc.getRoot().getChild( 0 ).getChild( 1 );
+
+			expect( textNode ).to.not.be.null;
+			expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
+
+			model.change( writer => {
+				const paragraph = doc.getRoot().getChild( 0 );
+
+				writer.setSelection( paragraph, 6 );
+				writer.setSelectionAttribute( 'bold', true );
+
+				writer.insertText( 'a', doc.selection.getAttributes(), writer.createPositionAt( paragraph, 6 ) );
+			} );
+
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph>foo @J<$text bold="true">a</$text>ohn bar</paragraph>' );
+		} );
+
 		it( 'should remove mention on removing a text at the beginning of a mention', () => {
 			editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );