I'm using CKEditor version 16 in an Angular 7 application. I have set maximum character length to 4096. Once user trying to type 4097th character control goes to starting and showing whatever typed from beginning until keyup or produce delay in typing. Later extra character showed on beginning will be automatically deleted.
I have tried setting editorConfig properties and It didn't worked out. I have crossed checked any timeout code is the cause of this issue and it is not.
CKEDITOR.editorConfig = function( config ) {
config.startupFocus= true;
config.extraPlugins = 'wordcount';
config.wordcount = {
showWordCount: false,
showCharCount: true,
maxCharCount: 4096,
showParagraphs: false,
countSpacesAsChars: true
};
config.pasteFromWordRemoveFontStyles = false;
config.pasteFromWordRemoveStyles = false;
config.extraAllowedContent= 'a[href]';
config.removePlugins = 'resize';
config.enterMode = CKEDITOR.ENTER_BR;
config.autoParagraph = false;
};
You can try by accessing ck editor instance.
CKEDITOR.instance.editor1.on("key", function (evt){
let instance = CKEDITOR.instance.editor1
const data = instance.document.getBody().getText();
const currentCount = data.replace(/<[^>]*>|\s/g, "").length;
const maxCount = instance.config.wordcount.maxCharCount;
const isFunKey = (evt.data.keyCode === 8 || evt.data.keyCode === 46 ||
evt.data.keyCode === 35 || evt.data.keyCode === NumberConstants.36 ||
evt.data.keyCode === 37 || evt.data.keyCode === 38 ||
evt.data.keyCode === 39 || evt.data.keyCode === 40 ||
evt.data.keyCode === 1114129 );
if (currentCount >= maxCount) {
if (!isFunKey) {
evt.cancel();
}
}
})
If you have more editor, you can loop through the instance and update the code accordingly.