ProseMirror is retaining its representation of the selection when the node view gets focused (because it doesn’t know anything about the meaning of the selection/focus inside that). You can work around this by having the code editor update the ProseMirror selection when it receives focus, as I did in this patch, where I set it to a node selection on the code block. You could even make it update the ProseMirror selection to the precise character position of the code editor selection whenever that changes, but I figured that in that demo, there’s not much value in that.