ソースを参照

Match mention at the beginning of a paragraph.

Maciej Gołaszewski 6 年 前
コミット
5fbca2e49c

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

@@ -82,7 +82,7 @@ export default class MentionEditing extends Plugin {
 
 						const mention = nodeBefore.getAttribute( 'mention' );
 
-						const name = mention.name || mention;
+						const name = mention.name;
 
 						const textName = text.slice( 1 );
 

+ 5 - 3
packages/ckeditor5-mention/src/mentionui.js

@@ -307,7 +307,9 @@ function getBalloonPanelPositions() {
 }
 
 function createPattern( marker ) {
-	return ` (${ marker })([\\w]*?)$`;
+	const numberOfCharacters = '*';
+
+	return `(^| )(${ marker })([_a-zA-Z0-9À-ž]${ numberOfCharacters }?)$`;
 }
 
 function createTestCallback( marker ) {
@@ -322,8 +324,8 @@ function createTextMatcher( marker ) {
 	return text => {
 		const match = text.match( regExp );
 
-		const marker = match[ 1 ];
-		const feedText = match[ 2 ];
+		const marker = match[ 2 ];
+		const feedText = match[ 3 ];
 
 		return { marker, feedText };
 	};

+ 27 - 0
packages/ckeditor5-mention/tests/mentionui.js

@@ -197,6 +197,33 @@ describe( 'MentionUI', () => {
 					} );
 			} );
 
+			it( 'should show panel for matched marker at the beginning of paragraph', () => {
+				setData( model, '<paragraph>[] foo</paragraph>' );
+
+				model.change( writer => {
+					writer.insertText( '@', doc.selection.getFirstPosition() );
+				} );
+
+				return waitForDebounce()
+					.then( () => {
+						expect( panelView.isVisible ).to.be.true;
+						expect( listView.items ).to.have.length( 5 );
+					} );
+			} );
+
+			it( 'should not show panel for marker in the middle of other word', () => {
+				setData( model, '<paragraph>foo[]</paragraph>' );
+
+				model.change( writer => {
+					writer.insertText( '@', doc.selection.getFirstPosition() );
+				} );
+
+				return waitForDebounce()
+					.then( () => {
+						expect( panelView.isVisible ).to.be.false;
+					} );
+			} );
+
 			it( 'should show filtered results for matched text', () => {
 				setData( model, '<paragraph>foo []</paragraph>' );