Reproable on the demo site. I made a pull request that fixes the issue.
Link to PR
Basically, the runInOp is wrapped around the addNewLineAndIndent function so the new line ends up being created and moved to after we go into insert mode which is muddling things up. I just wrapped the enterInsertMode function in a timeout to push it to the next run loop so all the operations should have finished.