Prevent Keyboard from opening when using selection.addRange()

What I am trying to achieve is similar to this set caret position stackoverflow thread. However, I don’t want the soft keyboard to pop up when I do that. Does anyone know any way around it?

I tried to listen to focus event on the contenteditable but focus event is not triggered.

You can simulate the behaviour via the link below.