Page 1 of 1

How to find the element inside cursor is placed

Posted: Fri Aug 26, 2022 10:28 am
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

Re: How to find the element inside cursor is placed

Posted: Mon Aug 29, 2022 9:11 am
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