Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get character index on right click for CodeArea

I am using CodeArea from RichTextFX in my code editor. I need to show context menu on right click and fill it based on the text where mouse is pointing. Like if I right click a function call, there will be "Go to declaration" in the context menu. To do that I need to get character index where the mouse is pointing. For MouseOverTextEvent there is the getCharacterIndex() method, but there is no such method in ContextMenuEvent or MouseEvent.

Saving the last index from MouseOverTextEvent is not a good option for me because I use MouseOverTextEvent for showing popup messages and this event has a 1 second delay (used setMouseOverTextDelay).

How can I get the character index for this right click event?

like image 531
Maxim.F Avatar asked Nov 22 '25 14:11

Maxim.F


1 Answers

The hit(...) method inherited from GenericStyledArea gives you access to the index of the closest character, given the x and y coordinates in the code area's coordinate system (which you can readily get from the mouse event).

like image 144
James_D Avatar answered Nov 24 '25 23:11

James_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!