How to find offset from line and column number

Post here questions and problems related to oXygen frameworks/document types.
Isabelle
Posts: 78
Joined: Fri Jan 20, 2017 1:11 pm

How to find offset from line and column number

Post by Isabelle » Thu Jun 17, 2021 9:55 pm

Hello,

I work with the version 22 of Oxygen SDK and I wonder how can I retrieve the offset from a line number and column number.

I have found the method getOffsetOfLineStart from the class WSTextEditorPage but the offset return is out of the document.
Exemple with the line 80, I get an offset of 3352 but the endOffset of the root element is 172.

Is there a way the have the good offset ?

Thanks in advanced,
Regards,
Isabelle

adrian_sorop
Posts: 20
Joined: Wed Jun 22, 2016 2:48 pm

Re: How to find offset from line and column number

Post by adrian_sorop » Fri Jun 18, 2021 6:14 pm

Hi Isabelle,

I don't fully understand your use case, but I'm assuming it's something like:

You have a nodeRange (ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextNodeRange) and you want to find the start and end offset of the node mapped in that range.

Your code will be something like:

Code: Select all

    WSXMLTextEditorPage textEditorPage = ...;
    WSXMLTextNodeRange nodeRange = ...;
    try {
      int startOffset = textEditorPage.getOffsetOfLineStart(nodeRange.getStartLine()) + nodeRange.getStartColumn() - 1;
      int endOffset = textEditorPage.getOffsetOfLineStart(nodeRange.getEndLine()) + nodeRange.getEndColumn() - 1;
      
    } catch (BadLocationException e) {
      // handle the exception
      e.printStackTrace();
    }
Let me know if this helps you,
Adrian S.
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com

Isabelle
Posts: 78
Joined: Fri Jan 20, 2017 1:11 pm

Re: How to find offset from line and column number

Post by Isabelle » Fri Jun 18, 2021 6:41 pm

Hi Adrian,

I will try and let you know.

Thank you.
Regards,
Isabelle

Post Reply