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

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

parent df1824bc
Branches
Tags
No related merge requests found
Pipeline #185133 failed
......@@ -414,14 +414,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();
let 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