Page 1 of 1

How to find offset from line and column number

Posted: Thu Jun 17, 2021 9:55 pm
by Isabelle
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

Re: How to find offset from line and column number

Posted: Fri Jun 18, 2021 6:14 pm
by adrian_sorop
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.

Re: How to find offset from line and column number

Posted: Fri Jun 18, 2021 6:41 pm
by Isabelle
Hi Adrian,

I will try and let you know.

Thank you.
Regards,
Isabelle