You’re totally right that the current implementation leaves something to be desired.
I like your proposal at first glance, but how does it behave when selecting a word at the right edge (“pretty” in this case for example), or a bigger chunk of text? Both situations could push it off screen too. In general, positioning of these things is often the hard part.
I’d love to see it in action too, in addition to screenshots, if possible.
(But we should def fix the current horizontal overflow tho!)