How to find the element inside cursor is placed

Having trouble installing Oxygen? Got a bug to report? Post it all here.
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

How to find the element inside cursor is placed

Post by SmitaPatil »

Hi Team,
I want to find the element name inside which user has placed cursor. Can you please if there is any existing method to get that?

Thanks,
Smita
mihaela
Posts: 515
Joined: Wed May 20, 2009 2:40 pm

Re: How to find the element inside cursor is placed

Post by mihaela »

Hello,

If you are developing a plugin or an AuthorOperation you can use the following Java API to find an element at a specific offset:
ro.sync.ecss.extensions.api.AuthorDocumentController.getNodeAtOffset(int)
The caret offset can be obtained from the AuthorEditorAccess:
authorAccess.getEditorAccess().getCaretOffset()
Then, to obtain the name of the element you can check first if the AuthorNode is an AuthorElement and get its local name with:
ro.sync.ecss.extensions.api.node.AuthorElement.getLocalName()

If this is not what you need please give us more details about your use case and the API that you use.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply