Skip to main content
3-Newcomer
April 9, 2024
Question

Absolute Offset of Selected Text

  • April 9, 2024
  • 1 reply
  • 2709 views

We are currently using Arbortext 8.2 and would like to know how we can get the absolute offset (starting from the top of the document) of selected/highlighted text. We have tried looking into the ACL commands and have not found any.

Any help with how to achieve this will be highly appreciated.

Thanks,

Willy.

1 reply

16-Pearl
April 9, 2024

Arbortext implements what is known as the Arbortext Object Model (AOM) which is actually a superset of DOM Level 2. The idea is you use the AOM methods to work with your document. For example, the ADocument interface provides a textSelection attribute to get the DOM Range for the user's cursor selection: https://support.ptc.com/help/arbortext/r8.2.1.0/en/index.html#page/Program/programmer_ref/adocument_textselection.html

 

Using the returned Range you can then find out startOffset, endOffset, etc.

 

I'm not sure if that's exactly what you're after but hopefully puts you on the right path.

3-Newcomer
April 11, 2024

I have tried using this but it's not what we want. It returns the offset of the selected text in the current element. In our case, we need to get the start and end offset of the text in the context of the whole document.


I would like to ask if there is any we can get the XPath of the element with selected text.

16-Pearl
April 12, 2024

Oh in that case I'm not sure the AOM methods will suit. You can explore ACL methods oid_offset, oid_caret_pos, and oid_caret_offset.

For calculating XPath of the selected text that is not available as an Arbortext method but you could write your own function to do that using the oid_*

methods.

I am curious what you are trying to achieve as there may be an alternative or better way to implement the functionality.