On my computer, your example exhibits the same problem as the code I wrote. The custom button inserts the text, even when a long string of text is selected.
Thank you,
-Ken W