Like this:
app.workspace.activeLeaf.view.editor.focus()
You might also find some useful concepts in the post I just made here: