OK I have to say I have never thought about what should happen if you try to select a sequence of text that mixes rtl and ltr languages. It's deeply in my mental zone of "undefined behavior, I don't even have an intuition about what to do."
One of the more fun programming projects I ever worked on was a custom text editor. Mainly it supported rich annotations that could be applied to any chosen term or stretch of text. It used Mobiledoc[1] which already provided pretty well-developed primitives for rich text editing on the web, and it was still a complicated project, even with a solid framework.