I am using CodeMirror v6 in javascript. I found https://discuss.codemirror.net/t/how-to-auto-focus-when-the-editor-loaded/5891/ and wrote this:
function autofocus(editor, info) {
console.log(1);
editor.focus();
}
editor = CodeMirror(document.getElementById("code_area"), {
lineNumbers: true,
...
});
editor.on("blur", autofocus);
It worked at first, but when I clicked for the second time, the function didn’t work. I don’t know why.