How to distinguish if there is text selected

I never noticed that before. I can see how it could be useful, but it certainly is a quirk!

If you are willing to learn the Obsidian API, maybe there are some answers for you. Get current text selection

(But I don’t know how.)