0

In my eclipse plugin, I have a StyledText object and IEditorReference object. I also have a yCoordinate that I want to use to check which line number is below this coordinate:

        int lineIndex = styledText.getLineIndex(yCoordinate);

This works fine, if there is no line folding applied. Therefore I'm looking for a method that takes either line folding into account, or that gives me back all the folded lines so that I can manually adjust the lineIndex. What are my options?

user6189
  • 653
  • 1
  • 7
  • 15

1 Answers1

2

From the IEditorReference you can get the IEditorPart

IEditorPart part = ref.getEditor(false);

If the part is an ITextEditor you can do the following:

ITextEditor editor = (ITextEditor)part;

IDocumentProvider provider = editor.getDocumentProvider();

IEditorInput input = editor.getEditorInput();

IDocument document = provider.getDocument(input);

int line = document.getLineOfOffset(offset in text);

'offset in text' is the number of characters from the start of the document. StyledText has a number of methods to get this value, for example getOffsetAtLocation(Point).

greg-449
  • 109,219
  • 232
  • 102
  • 145