Determines if the offset is between line numbers?

I need to determine if a given choice is between the start and end lines. I have an ILineRange and a given offset in the eclipse viewport. (I need to know if the selection (from the far side) was made in the current view window of the local user. Unfortunately, I cannot get ILineRange from the selection. I have to rely on getOffset () and getLength () ...
Does anyone have an idea?
I think there is no clean solution for this, since the offset (or characters per line are different (new lines or a large block of comments).

+4
source share
2 answers

Converting positions and offsets can be done using the IDocument API (methods around getLine * ()). (I'm not sure I fully understood your question, but I hope this is useful information.)

+1
source

Perhaps you can check if this org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STOverviewRuler class has the same problem that you have.
Sort of:

 if (ANNOTATION_HEIGHT_SCALABLE) { int numbersOfLines= document.getNumberOfLines(annotationOffset, annotationLength); // don't count empty trailing lines IRegion lastLine= document.getLineInformationOfOffset(annotationOffset + annotationLength); if (lastLine.getOffset() == annotationOffset + annotationLength) { numbersOfLines -= 2; hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT; if (hh < ANNOTATION_HEIGHT) hh= ANNOTATION_HEIGHT; } else hh= ANNOTATION_HEIGHT; } fAnnotationHeight= hh; int startLine= textWidget.getLineAtOffset(annotationOffset - visible.getOffset()); yy= Math.min((startLine * size.y) / maxLines, size.y - hh); 
+1
source

Source: https://habr.com/ru/post/1304563/


All Articles