The ITextViewer
object (or the ISourceViewer
extension) has a getSelectedRange()
method which returns you a Point
containing the offset in the document and the length of the selected range.
The IDocument
object has a getLineOfOffset()
method which returns the line containing an offset. It also has getLineInformationOfOffset()
returning information about the line.
So:
Point selected = textViewer.getSelectedRange();
int line = document.getLineOfOffset(selected.x);
IRegion lineRegion = document.getLineInformationOfOffset(selected.x);
int col = selected.x - lineRegion.getOffset();