How to customize the text selection tooltip

Hi, Thanks a lot.
But can you please share me how to get the instance and where the event generating after selected some text.
Means where i need to add the code given by you.