Here's what I want: In Google Sheets, when I'm editing the contents of a cell, I want to be able to select some of contents (by clicking and dragging), and then run a macro that will modify the selected text in some way (say, add something before and after the selection). Note that I don't want the contents of the whole cell, just the selected text in that cell.
I've searched a lot and I can't quite find how to do this with the APIs and a script. It seems maybe possible with Google Docs, but I'm looking for this in Google Sheets.
Is there a way to do this?
edit: more specifically, is there an API function to get the currently selected text?
I've seen these (and many other) posts and they are not what I'm asking: