How to autofocus in CodeMirror.js

I am using CodeMirror v6 in javascript. I found and wrote this:

function autofocus(editor, info) {

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.

I’m not sure what went wrong with that, but refocusing the editor when the user is trying to move focus elsewhere doesn’t seem like a very good idea to begin with.

OK. Maybe I should refocus when a button is pressed.

But I still wonder why it didn’t work.