use of org.eclipse.jface.text.source.ILineRange in project eclipse.platform.text by eclipse.
the class RangeUtil method deepClone.
static List<Range> deepClone(List<Range> ranges) {
List<Range> list = new ArrayList<>(ranges.size());
for (Iterator<Range> it = ranges.iterator(); it.hasNext(); ) {
ILineRange range = it.next();
list.add(Range.copy(range));
}
return list;
}
use of org.eclipse.jface.text.source.ILineRange 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.source.ILineRange in project eclipse.platform.text by eclipse.
the class RevisionPainter method handleMouseWheel.
/**
* Handles a mouse wheel event.
*
* @param event the mouse wheel event
*/
private void handleMouseWheel(Event event) {
boolean up = event.count > 0;
int documentHoverLine = fFocusLine;
ILineRange nextWidgetRange = null;
ILineRange last = null;
List<RevisionRange> ranges = fFocusRevision.getRegions();
if (up) {
for (RevisionRange range : ranges) {
ILineRange widgetRange = modelLinesToWidgetLines(range);
if (contains(range, documentHoverLine)) {
nextWidgetRange = last;
break;
}
if (widgetRange != null)
last = widgetRange;
}
} else {
for (ListIterator<RevisionRange> it = ranges.listIterator(ranges.size()); it.hasPrevious(); ) {
RevisionRange range = it.previous();
ILineRange widgetRange = modelLinesToWidgetLines(range);
if (contains(range, documentHoverLine)) {
nextWidgetRange = last;
break;
}
if (widgetRange != null)
last = widgetRange;
}
}
if (nextWidgetRange == null)
return;
int widgetCurrentFocusLine = modelLinesToWidgetLines(new LineRange(documentHoverLine, 1)).getStartLine();
int widgetNextFocusLine = nextWidgetRange.getStartLine();
int newTopPixel = fWidget.getTopPixel() + JFaceTextUtil.computeLineHeight(fWidget, widgetCurrentFocusLine, widgetNextFocusLine, widgetNextFocusLine - widgetCurrentFocusLine);
fWidget.setTopPixel(newTopPixel);
if (newTopPixel < 0) {
Point cursorLocation = fWidget.getDisplay().getCursorLocation();
cursorLocation.y += newTopPixel;
fWidget.getDisplay().setCursorLocation(cursorLocation);
} else {
int topPixel = fWidget.getTopPixel();
if (topPixel < newTopPixel) {
Point cursorLocation = fWidget.getDisplay().getCursorLocation();
cursorLocation.y += newTopPixel - topPixel;
fWidget.getDisplay().setCursorLocation(cursorLocation);
}
}
updateFocusLine(toDocumentLineNumber(fWidget.toControl(fWidget.getDisplay().getCursorLocation()).y));
immediateUpdate();
}
use of org.eclipse.jface.text.source.ILineRange in project eclipse.platform.text by eclipse.
the class Revision method getRegions.
/**
* Returns the contained {@link RevisionRange}s adapted to the current diff state. The returned
* information is only valid at the moment it is returned, and may change as the annotated
* document is modified.
*
* @return an unmodifiable view of the contained ranges
*/
public final List<RevisionRange> getRegions() {
if (fRanges == null) {
List<RevisionRange> ranges = new ArrayList<>(fChangeRegions.size());
for (ChangeRegion region : fChangeRegions) {
for (ILineRange range : region.getAdjustedRanges()) {
ranges.add(new RevisionRange(this, range));
}
}
fRanges = Collections.unmodifiableList(ranges);
}
return fRanges;
}
use of org.eclipse.jface.text.source.ILineRange in project eclipse.platform.text by eclipse.
the class RangeUtil method assertEqualRanges.
static void assertEqualRanges(List<Range> expected, List<Range> actual) {
assertEquals(expected.size(), actual.size());
Iterator<Range> it1 = expected.iterator();
Iterator<Range> it2 = actual.iterator();
while (it1.hasNext()) {
ILineRange r1 = it1.next();
ILineRange r2 = it2.next();
assertEqualRange(r1, r2);
}
}
Aggregations