mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-28 21:22:30 +00:00
Updated tinymce code block handling to help prevent breaking history states
Only used an undo transaction on startup and added a small delay to codeMirror parsing on SetContent's to help avoid the rendering activities getting caught in undoManager states. Seemed to improve things a lot in Firefox & chrome on my dev machine. For #2602
This commit is contained in:
parent
9df4dee1b2
commit
70be28d22c
@ -152,8 +152,8 @@ function codePlugin() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lang = selectedNode.hasAttribute('data-lang') ? selectedNode.getAttribute('data-lang') : '';
|
const lang = selectedNode.hasAttribute('data-lang') ? selectedNode.getAttribute('data-lang') : '';
|
||||||
let currentCode = selectedNode.querySelector('textarea').textContent;
|
const currentCode = selectedNode.querySelector('textarea').textContent;
|
||||||
|
|
||||||
window.components.first('code-editor').open(currentCode, lang, (code, lang) => {
|
window.components.first('code-editor').open(currentCode, lang, (code, lang) => {
|
||||||
const editorElem = selectedNode.querySelector('.CodeMirror');
|
const editorElem = selectedNode.querySelector('.CodeMirror');
|
||||||
@ -225,22 +225,23 @@ function codePlugin() {
|
|||||||
return elem.contentEditable !== "false";
|
return elem.contentEditable !== "false";
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!codeSamples.length) return;
|
codeSamples.each((index, elem) => {
|
||||||
editor.undoManager.transact(function () {
|
Code.wysiwygView(elem);
|
||||||
codeSamples.each((index, elem) => {
|
|
||||||
Code.wysiwygView(elem);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.on('init', function() {
|
editor.on('init', function() {
|
||||||
// Parse code mirror instances on init, but delay a little so this runs after
|
// Parse code mirror instances on init, but delay a little so this runs after
|
||||||
// initial styles are fetched into the editor.
|
// initial styles are fetched into the editor.
|
||||||
parseCodeMirrorInstances();
|
editor.undoManager.transact(function () {
|
||||||
|
parseCodeMirrorInstances();
|
||||||
|
});
|
||||||
// Parsed code mirror blocks when content is set but wait before setting this handler
|
// Parsed code mirror blocks when content is set but wait before setting this handler
|
||||||
// to avoid any init 'SetContent' events.
|
// to avoid any init 'SetContent' events.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
editor.on('SetContent', parseCodeMirrorInstances);
|
editor.on('SetContent', () => {
|
||||||
|
setTimeout(parseCodeMirrorInstances, 100);
|
||||||
|
});
|
||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user