Parcourir la source

Bind the feed callback function to the editor instance

Oliver Günther il y a 6 ans
Parent
commit
7c64d7396c

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

@@ -135,7 +135,7 @@ export default class MentionUI extends Plugin {
 			}
 
 			const minimumCharacters = mentionDescription.minimumCharacters || 0;
-			const feedCallback = typeof feed == 'function' ? feed : createFeedCallback( feed );
+			const feedCallback = typeof feed == 'function' ? feed.bind( this.editor ) : createFeedCallback( feed );
 			const watcher = this._setupTextWatcherForFeed( marker, minimumCharacters );
 			const itemRenderer = mentionDescription.itemRenderer;
 

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

@@ -852,6 +852,37 @@ describe( 'MentionUI', () => {
 			} );
 		} );
 
+		describe( 'callback function using data from editor', () => {
+			beforeEach( () => {
+				return createClassicTestEditor( {
+					feeds: [
+						{
+							marker: '#',
+							feed() {
+								expect( this ).to.equal( editor );
+								return Promise.resolve( [ 'foo', 'bar' ] );
+							}
+						}
+					]
+				} );
+			} );
+
+			it( 'should bind the instance panel for matched marker', () => {
+				setData( model, '<paragraph>foo []</paragraph>' );
+
+				model.change( writer => {
+					writer.insertText( '#', doc.selection.getFirstPosition() );
+				} );
+
+				return waitForDebounce()
+					.then( () => {
+						expect( panelView.isVisible ).to.be.true;
+						expect( editor.model.markers.has( 'mention' ) ).to.be.true;
+						expect( mentionsView.items ).to.have.length( 2 );
+					} );
+			} );
+		} );
+
 		describe( 'asynchronous list with custom trigger', () => {
 			beforeEach( () => {
 				const issuesNumbers = [ '#100', '#101', '#102', '#103' ];