Ckeditor5: How to listen for 'mention added' event?

Created on 8 Jul 2020  路  4Comments  路  Source: ckeditor/ckeditor5

It is not a bug, but there is no Question Issue.

The question is: How can I listen for an event 'mention added' or something like that? I need to know when a mention is added. How can I achieve that?

question

All 4 comments

Hi @hpivanov , you can start with code like this:

editor.conversion.for( 'downcast' ).add( dispatcher => {
    dispatcher.on( 'attribute:mention', ( evt, data, conversionApi ) => {
        console.log( 'Mention has been inserted' );
        console.log( data );
    }, { priority: 'low' } );
} );

This will be fired every time you insert a mention, or some other content which has mention attribute in the model. If you need some more info, please refer to docs on:

Hope that helps!

This works, but it fires even when I get the data from the editor using getData(). I just need to know that I have clicked on an item from the dropdown menu, that's it.

@hpivanov, in this case, you can simply add a dispatcher for editingDowncast, instead of downcast (which is for editing and data pipelines).

@Mgsy Thanky you. That is what I was looking for :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pjasiun picture pjasiun  路  3Comments

devaptas picture devaptas  路  3Comments

oleq picture oleq  路  3Comments

MansoorJafari picture MansoorJafari  路  3Comments

Reinmar picture Reinmar  路  3Comments