Commit 6555c338 authored by jonnybradley's avatar jonnybradley

[FIX] codemirror: Hasn't been updating the preview and auto save info since...

[FIX] codemirror: Hasn't been updating the preview and auto save info since upgrade to version 2.x - so fix that and improve handling so it updates after 25 chars have been changed, or after 2 seconds
parent eb55511e
Pipeline #51015976 failed with stages
in 27 minutes and 25 seconds
......@@ -342,37 +342,48 @@ var syntaxHighlighter;
syntaxHighlighter = {
modes: {},
ready: function (textarea, settings, mode) {
var changeCount = 0;
var changeCount = 0,
previewTimer = null,
previewDelay = 5000,
updateAutoSaveAndPreview = function () {
textarea.val(editor.getValue()).change();
if (window.auto_save) {
auto_save(textarea.attr('id'));
}
},
editor = CodeMirror.fromTextArea(textarea[0], {
stylesheet: 'default',
lineNumbers: settings.lineNumbers,
readOnly: settings.readOnly,
mode: mode,
lineWrapping: settings.lineWrapping,
theme: settings.theme === "off" ? "default" : settings.theme
});
settings = $.extend({
changeText: tr("Change Highlighter"),
removeText: tr("Toggle Highlighter")
}, settings);
var editor = CodeMirror.fromTextArea(textarea[0], {
stylesheet: 'default',
onChange: function () {
//Setup codemirror to send the text back to the textarea
changeCount++;
if (changeCount > 50) {
if (window.auto_save) {
auto_save(textarea.attr('id'));
}
textarea.val(editor.getValue()).change();
changeCount = 0;
}
},
onBlur: function () {
if (window.auto_save) {
textarea.val(editor.getValue()).change();
auto_save(textarea.attr('id'));
}
},
lineNumbers: settings.lineNumbers,
readOnly: settings.readOnly,
mode: mode,
lineWrapping: settings.lineWrapping,
theme: settings.theme == "off" ? "default" : settings.theme
editor.on("change", function (cm, change) {
previewDelay = 2000;
changeCount++;
if (previewTimer) {
clearTimeout(previewTimer);
}
if (changeCount > 25) {
changeCount = 0;
previewDelay = 100
}
previewTimer = setTimeout(updateAutoSaveAndPreview, previewDelay);
});
editor.on("blur", function () {
if (previewTimer) {
clearTimeout(previewTimer);
}
updateAutoSaveAndPreview();
});
if (settings.readOnly) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment