Find out beginning of node and its first child element

Having trouble installing Oxygen? Got a bug to report? Post it all here.
shilpa
Posts: 66
Joined: Mon Jul 04, 2022 8:42 am

Find out beginning of node and its first child element

Post 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
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

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

Post 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
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply