Made codemirror editor load a lot more efficient

Brings down total editor load time from about 11s to 7s from testing in
4x reduced CPU speed in chrome.
About 1.5 seconds of that is editor init/page load.
Post editor-init/page-load time is now 60% of previous from testing.

Related to #2518
This commit is contained in:
Dan Brown 2021-01-31 16:23:15 +00:00
parent 44c41e9e4d
commit bc1e84325c
2 changed files with 13 additions and 4 deletions

View File

@ -212,7 +212,7 @@ function codePlugin() {
showPopup(editor);
});
editor.on('SetContent', function () {
function parseCodeMirrorInstances() {
// Recover broken codemirror instances
$('.CodeMirrorContainer').filter((index ,elem) => {
@ -231,6 +231,17 @@ function codePlugin() {
Code.wysiwygView(elem);
});
});
}
editor.on('init', function() {
// Parse code mirror instances on init, but delay a little so this runs after
// initial styles are fetched into the editor.
parseCodeMirrorInstances();
// Parsed code mirror blocks when content is set but wait before setting this handler
// to avoid any init 'SetContent' events.
setTimeout(() => {
editor.on('SetContent', parseCodeMirrorInstances);
}, 200);
});
});

View File

@ -238,9 +238,7 @@ function wysiwygView(elem) {
theme: getTheme(),
readOnly: true
});
setTimeout(() => {
cm.refresh();
}, 300);
return {wrap: newWrap, editor: cm};
}