use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class JavaEditor method adjustHighlightRange.
@Override
protected void adjustHighlightRange(int offset, int length) {
ISourceViewer viewer = getSourceViewer();
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
extension.exposeModelRange(new Region(offset, length));
}
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class RevisionPainter method modelLinesToWidgetLines.
/**
* Returns the visible extent of a document line range in widget lines.
*
* @param range the document line range
* @return the visible extent of <code>range</code> in widget lines
*/
private ILineRange modelLinesToWidgetLines(ILineRange range) {
int widgetStartLine = -1;
int widgetEndLine = -1;
if (fViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
int modelEndLine = end(range);
for (int modelLine = range.getStartLine(); modelLine < modelEndLine; modelLine++) {
int widgetLine = extension.modelLine2WidgetLine(modelLine);
if (widgetLine != -1) {
if (widgetStartLine == -1)
widgetStartLine = widgetLine;
widgetEndLine = widgetLine;
}
}
} else {
IRegion region = fViewer.getVisibleRegion();
IDocument document = fViewer.getDocument();
try {
int visibleStartLine = document.getLineOfOffset(region.getOffset());
int visibleEndLine = document.getLineOfOffset(region.getOffset() + region.getLength());
widgetStartLine = Math.max(0, range.getStartLine() - visibleStartLine);
widgetEndLine = Math.min(visibleEndLine, end(range) - 1);
} catch (BadLocationException x) {
// ignore and return null
}
}
if (widgetStartLine == -1 || widgetEndLine == -1)
return null;
return new LineRange(widgetStartLine, widgetEndLine - widgetStartLine + 1);
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class AnnotationBarHoverManager method getWidgetLineNumber.
/**
* Returns for the widget line number for the given document line number.
*
* @param line the absolute line number
* @return the line number relative to the viewer's visible region
* @throws BadLocationException if <code>line</code> is not valid in the viewer's document
*/
private int getWidgetLineNumber(int line) throws BadLocationException {
if (fSourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
return extension.modelLine2WidgetLine(line);
}
IRegion region = fSourceViewer.getVisibleRegion();
int firstLine = fSourceViewer.getDocument().getLineOfOffset(region.getOffset());
return line - firstLine;
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class AnnotationBarHoverManager method adaptLineRangeToFolding.
/**
* Adapts a given line range so that the result is a line range that does
* not overlap with any collapsed region of the attached viewer.
*
* @param lineRange the original line range
* @param line the anchor line
* @return the adapted line range
* @since 3.0
*/
private ILineRange adaptLineRangeToFolding(ILineRange lineRange, int line) {
if (fSourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
try {
IRegion region = convertToRegion(lineRange);
IRegion[] coverage = extension.getCoveredModelRanges(region);
if (coverage != null && coverage.length > 0) {
IRegion container = findRegionContainingLine(coverage, line);
if (container != null)
return convertToLineRange(container);
}
} catch (BadLocationException x) {
}
return null;
}
return lineRange;
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class AnnotationPainter method getWidgetRange.
/**
* Returns the widget region that corresponds to the
* given offset and length in the viewer's document.
*
* The returned object can be the fReusableRegion and may used
* only to read the return values and must not used to store
* the region.
*
* @param modelOffset the model offset
* @param modelLength the model length
* @return the corresponding widget region
*/
private IRegion getWidgetRange(int modelOffset, int modelLength) {
if (modelOffset == Integer.MAX_VALUE)
return null;
if (fSourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
fReusableRegion.setOffset(modelOffset);
fReusableRegion.setLength(modelLength);
return extension.modelRange2WidgetRange(fReusableRegion);
}
IRegion region = fSourceViewer.getVisibleRegion();
int offset = region.getOffset();
int length = region.getLength();
if (regionsTouchOrOverlap(modelOffset, modelLength, offset, length)) {
int p1 = Math.max(offset, modelOffset);
int p2 = Math.min(offset + length, modelOffset + modelLength);
fReusableRegion.setOffset(p1 - offset);
fReusableRegion.setLength(p2 - p1);
return fReusableRegion;
}
return null;
}
Aggregations