Skip to content
Snippets Groups Projects
Commit bb35429a authored by Adam Nagy's avatar Adam Nagy
Browse files

Issue #3382403: React only on 'change:data' editor event.

parent 3e19e130
No related branches found
No related tags found
1 merge request!48Issue #3382403: React only on 'change:data' editor event.
Pipeline #185085 canceled
......@@ -348,14 +348,15 @@
*/
ml.ckeditor5 = function (editor, options) {
$(once('maxlengthbinding', editor.sourceElement)).each(function() {
editor.model.document.on('change', function() {
if (editor.getData() !== editor.sourceElement.textContent) {
// Listen to changes to data only.
editor.model.document.on('change:data', function() {
let editorData = editor.getData();
if (editorData !== editor.sourceElement.textContent) {
// Trim if limit is reached and enforcing is activated.
if (options['enforce']) {
let maxlength = $(editor.sourceElement).data('maxlength');
let data = editor.getData();
const trimmed = ml.truncate_html(data, maxlength);
if (data.length !== trimmed.length) {
const trimmed = ml.truncate_html(editorData, maxlength);
if (editorData.length !== trimmed.length) {
editor.setData(trimmed);
setTimeout(() => {
editor.model.change( writer => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment