mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
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:
parent
44c41e9e4d
commit
bc1e84325c
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -238,9 +238,7 @@ function wysiwygView(elem) {
|
||||
theme: getTheme(),
|
||||
readOnly: true
|
||||
});
|
||||
setTimeout(() => {
|
||||
cm.refresh();
|
||||
}, 300);
|
||||
|
||||
return {wrap: newWrap, editor: cm};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user