From 91808a088b32f9847ea7a2dfe21439f4f14da09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 9 Sep 2019 09:18:27 +0200 Subject: [PATCH] Bind the feed callback function to the editor instance --- src/mentionui.js | 2 +- tests/mentionui.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/mentionui.js b/src/mentionui.js index ad8ae7c..796ad66 100644 --- a/src/mentionui.js +++ b/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; diff --git a/tests/mentionui.js b/tests/mentionui.js index 3ca330b..2bcce9b 100644 --- a/tests/mentionui.js +++ b/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, 'foo []' ); + + 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' ];