Page 1 of 1

Find out beginning of node and its first child element

Posted: Mon Jan 02, 2023 12:35 pm
by shilpa
Hi Team,

How to find out cursor is at the beginning of the node and also find out the is it first child of element?
Below is the example
Here say suppose my cursor is at <figure> then i should know its beginning of node and say suppose my cursor is at first <para>
then i should know its first child and last child of <figure> how to achieve this?
Example
<figure>
<para>
<paratext>Test</paratext>
<paratext>Test1</paratext>
</para>
<para>
<paratext>Test</paratext>
<paratext>Test1</paratext>
</para>
<figure>
Thanks & Regards
Shilpa.P

Re: Find out beginning of node and its first child element

Posted: Tue Jan 03, 2023 10:14 am
by mihaela
Hi,

1. You can use the ro.sync.ecss.extensions.api.AuthorDocumentController.getContentInformationAtOffset(int) API to find if a specific offset corresponds to a start or an end sentinel of a node. Here is an example of the returned OffsetInformation, when the caret is placed at the beginning, in the content or at the end of a node:
Image
To find the offset corresponding to the cursor you can use the ro.sync.ecss.extensions.api.access.AuthorEditorAccess.getCaretOffset() API.

2. From the OffsetInformation returned by the mentioned API method you can also find the node at caret (use OffsetInformation.getNodeForMarkerOffset() or OffsetInformation.getNodeForOffset(), depending on the position returned by the OffsetInformation.getPositionType() method). Then, you can find its parent using the ro.sync.ecss.extensions.api.node.AuthorNode.getParent() API and check the (start and end) offsets of each node to see if the node at caret is the first or last child in parent.

Best Regards,
Mihaela