ソースを参照

Make default feed callback return up to 10 items.

Maciej Gołaszewski 6 年 前
コミット
830033b3c9

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

@@ -469,9 +469,11 @@ function createTextMatcher( marker ) {
 // Default feed callback
 function createFeedCallback( feedItems ) {
 	return feedText => {
-		const filteredItems = feedItems.filter( item => {
-			return item.toLowerCase().includes( feedText.toLowerCase() );
-		} );
+		const filteredItems = feedItems
+		// Make default mention feed case-insensitive.
+			.filter( item => item.toLowerCase().includes( feedText.toLowerCase() ) )
+			// Do not return more then 10 items.
+			.slice( 0, 10 );
 
 		return Promise.resolve( filteredItems );
 	};

+ 7 - 0
packages/ckeditor5-mention/tests/manual/mention.js

@@ -30,6 +30,13 @@ ClassicEditor
 		mention: {
 			feeds: [
 				{ feed: [ 'Barney', 'Lily', 'Marshall', 'Robin', 'Ted' ] },
+				{
+					marker: '#',
+					feed: [
+						'a01', 'a02', 'a03', 'a04', 'a05', 'a06', 'a07', 'a08', 'a09', 'a10',
+						'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a17', 'a18', 'a19', 'a20'
+					]
+				}
 			]
 		}
 	} )

+ 13 - 7
packages/ckeditor5-mention/tests/manual/mention.md

@@ -4,13 +4,19 @@ The minimal mention configuration with a static list of autocomplete feed:
 
 ### Configuration
 
-The feed:
-
-- Barney
-- Lily
-- Marshall
-- Robin
-- Ted
+The feeds:
+
+1. Static list with `@` marker:
+    - Barney
+    - Lily
+    - Marshall
+    - Robin
+    - Ted
+2. Static list of 20 items (`#` marker)
+    - a01
+    - a02
+    - ... 
+    - a20
 
 ### Interaction
 

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

@@ -218,6 +218,29 @@ describe( 'MentionUI', () => {
 				} );
 		} );
 
+		it( 'should show panel with no more then 10 items for default static feed', () => {
+			const bigList = {
+				marker: '@',
+				feed: [
+					'a01', 'a02', 'a03', 'a04', 'a05', 'a06', 'a07', 'a08', 'a09', 'a10', 'a11', 'a12'
+				]
+			};
+
+			return createClassicTestEditor( { feeds: [ bigList ] } )
+				.then( () => {
+					setData( model, '<paragraph>foo []</paragraph>' );
+
+					model.change( writer => {
+						writer.insertText( '@', doc.selection.getFirstPosition() );
+					} );
+				} )
+				.then( waitForDebounce )
+				.then( () => {
+					expect( panelView.isVisible ).to.be.true;
+					expect( listView.items ).to.have.length( 10 );
+				} );
+		} );
+
 		describe( 'static list with default trigger', () => {
 			beforeEach( () => {
 				return createClassicTestEditor( staticConfig );