It's a good idea. I'm not aware of a built in way to do this but it's the perfect job for an add-in. I searched quickly for an existing add-in that does this but didn't find one - you might.
Anyway it's not too difficult to write your own add-in. See my recent comment here on another thread - use the rstudioapi package to see how to access selected text.
See also this blog post