Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #86 from oliverguenther/patch-1
Browse files Browse the repository at this point in the history
Other: Bind the `feed` callback function to the editor instance.

Thanks @oliverguenther for the contribution!
  • Loading branch information
Reinmar authored Sep 10, 2019
2 parents 8e0c8bd + 91808a0 commit 0ba40a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
31 changes: 31 additions & 0 deletions tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
Expand Down

0 comments on commit 0ba40a9

Please sign in to comment.