I implemented an autosave functionality (details below), but any time it fires calling getValue(), the cursor jumps to the top-left corner. This happens with CM version 5.28 and 5.27. I don’t remember this happening before. Thanks for helping me! Mario
CodeMirror 5.28 on Windows under Chrome latest. Parameters:
mode: "markdown",
lineNumbers: false,
lineWrapping: true,
theme: "blackboard",
scrollbarStyle: null,
autoRefresh: true,
extraKeys: {
...
},
foldGutter: true,
gutters: ["CodeMirror-foldgutter"]
The autosave code is (simplified):
// When content edited
editor.on("change", function(event, changeObj) {
// If content save already queued or change due to loading, ignore
if(saveTimerID !== null || (changeObj.origin !== undefined && changeObj.origin === "setValue")) return;
// Collect changes for the next 5 seconds
saveTimerID = setTimeout(function() {
let text = editor.getValue();
// Do the save of text
saveTimerID = null;
}, 5000);
});