use of org.eclipse.jface.text.source.LineRange in project eclipse.platform.text by eclipse.
the class ChangeRegionTest method testHunkBefore.
@Test
public void testHunkBefore() throws Exception {
ChangeRegion r;
r = new ChangeRegion(fRevision, new LineRange(12, 3));
r.adjustTo(new Hunk(5, 3, 2));
RangeUtil.assertEqualSingleRange(new LineRange(15, 3), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(15, 3), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 3));
r.adjustTo(new Hunk(5, 3, 0));
RangeUtil.assertEqualSingleRange(new LineRange(15, 3), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(15, 3), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 3));
r.adjustTo(new Hunk(5, -3, 0));
RangeUtil.assertEqualSingleRange(new LineRange(9, 3), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(9, 3), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 3));
r.adjustTo(new Hunk(5, 3, 3));
RangeUtil.assertEqualSingleRange(new LineRange(15, 3), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(15, 3), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 3));
r.adjustTo(new Hunk(5, -3, 2));
RangeUtil.assertEqualSingleRange(new LineRange(9, 3), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(9, 3), r.getAdjustedCoverage());
}
use of org.eclipse.jface.text.source.LineRange in project eclipse.platform.text by eclipse.
the class ChangeRegionTest method testHunkInBetween.
@Test
public void testHunkInBetween() throws Exception {
// TODO require merging of adjacent ranges?
ChangeRegion r;
r = new ChangeRegion(fRevision, new LineRange(12, 7));
r.adjustTo(new Hunk(15, -2, 0));
RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(15, 2), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(12, 5), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 7));
r.adjustTo(new Hunk(15, 2, 0));
RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(17, 4), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(12, 9), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 7));
r.adjustTo(new Hunk(15, 0, 2));
RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(17, 2), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(12, 7), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 7));
r.adjustTo(new Hunk(15, -1, 2));
RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(17, 1), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(12, 6), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 7));
r.adjustTo(new Hunk(15, 2, 2));
RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(19, 2), r.getAdjustedRanges());
RangeUtil.assertEqualRange(new LineRange(12, 9), r.getAdjustedCoverage());
}
use of org.eclipse.jface.text.source.LineRange 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.LineRange 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.LineRange in project eclipse.platform.text by eclipse.
the class ChangeRegionTest method testHunkAfter.
@Test
public void testHunkAfter() throws Exception {
ChangeRegion r = new ChangeRegion(fRevision, new LineRange(12, 3));
List<Range> before = RangeUtil.deepClone(r.getAdjustedRanges());
r.adjustTo(new Hunk(16, 3, 2));
RangeUtil.assertEqualRanges(before, r.getAdjustedRanges());
RangeUtil.assertEqualRange(before.get(0), r.getAdjustedCoverage());
r = new ChangeRegion(fRevision, new LineRange(12, 3));
before = RangeUtil.deepClone(r.getAdjustedRanges());
r.adjustTo(new Hunk(16, -33, 2));
RangeUtil.assertEqualRanges(before, r.getAdjustedRanges());
RangeUtil.assertEqualRange(before.get(0), r.getAdjustedCoverage());
}
Aggregations