1

I,m trying to build a mention plugin for ckeditor i started with this code

CKEDITOR.plugins.add('mention', {
    init: function (editor) {
        editor.on('key', function (event) {
            console.log(String.fromCharCode(event.data.keyCode));
        });
    }
});

The problem is keyCode property doesn't give an accurate result when it comes to getting the entered letter.

Is there a better way to get the entered letter accurately with respect to the language?

Muhamad Bhaa Asfour
  • 1,075
  • 3
  • 22
  • 39

2 Answers2

1

I didn't find any good solution for this problem at the end i used the At.js jquery plugin with the ckeditor for the mention functionality, So i'm leaving this answer as a future reference for anyone who need to implement a mention functionality with ckeditor.

Muhamad Bhaa Asfour
  • 1,075
  • 3
  • 22
  • 39
0

Sorry to say that but there's no perfect way to do so while the key is being pressed (on keydown). Handling typing is extremely difficult and is handled by the browsers and operating systems, because even with KeyboardEvent.key (which is not yet widely implemented) you need to take into consideration character composition (multiple key events composing into one character).

If it's OK for you to get the letter after it's inserted, you can get the selection from the editor and find preceding letter.

Reinmar
  • 21,729
  • 4
  • 67
  • 78