Skip to content

Commit

Permalink
fix(core): Add timer to avoid spamming onEditorChanged for CKEditor 5…
Browse files Browse the repository at this point in the history
…. Fixes #5944. Added onblur event
  • Loading branch information
WoodySlum committed Apr 8, 2024
1 parent 98e00d0 commit 2f4c125
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions UI/WebServerResources/js/Common/sgCkeditor.component.js
Expand Up @@ -288,9 +288,10 @@
// vm.editor.editing.view.domRoots.get("main").style.marginRight = vm.ckMargin;
// }

vm.editor.model.document.on('pasteState', onEditorChange);
vm.editor.model.document.on('change:data', onEditorChange);
vm.editor.model.document.on('paste', onEditorPaste);
vm.editor.model.document.on('pasteState', function () { onEditorChange(false); });
vm.editor.model.document.on('change:data', function () { onEditorChange(false); });
vm.editor.model.document.on('paste', function () { onEditorChange(false); });
editor.editing.view.document.on('blur', function () { onEditorChange(true); });

onInstanceReady();

Expand Down Expand Up @@ -340,11 +341,11 @@
vm.editor.destroy(noUpdate);
}

function onEditorChange() {
function onEditorChange(force) {
if (editorChangedTimer)
clearTimeout(editorChangedTimer);

editorChangedTimer = setTimeout(function () {
var refresh = function() {
var html = vm.editor.getData();

var dom = document.createElement("DIV");
Expand All @@ -369,7 +370,13 @@
}
modelChanged = false;
editorChangedTimer = null;
}, editorChangedTimerValue);
};

if (force) {
refresh();
} else {
editorChangedTimer = setTimeout(refresh, editorChangedTimerValue);
}
}

function onEditorPaste (event) {
Expand Down

0 comments on commit 2f4c125

Please sign in to comment.