Search in sources :

Example 6 with LineRange

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());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Example 7 with LineRange

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());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Example 8 with LineRange

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);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) LineRange(org.eclipse.jface.text.source.LineRange) ILineRange(org.eclipse.jface.text.source.ILineRange) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 9 with LineRange

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();
}
Also used : ILineRange(org.eclipse.jface.text.source.ILineRange) RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) Point(org.eclipse.swt.graphics.Point) LineRange(org.eclipse.jface.text.source.LineRange) ILineRange(org.eclipse.jface.text.source.ILineRange) Point(org.eclipse.swt.graphics.Point)

Example 10 with LineRange

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());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) Range(org.eclipse.jface.internal.text.revisions.Range) LineRange(org.eclipse.jface.text.source.LineRange) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Aggregations

LineRange (org.eclipse.jface.text.source.LineRange)18 Test (org.junit.Test)12 ChangeRegion (org.eclipse.jface.internal.text.revisions.ChangeRegion)11 Hunk (org.eclipse.jface.internal.text.revisions.Hunk)10 ILineRange (org.eclipse.jface.text.source.ILineRange)5 Range (org.eclipse.jface.internal.text.revisions.Range)3 IDocument (org.eclipse.jface.text.IDocument)3 Point (org.eclipse.swt.graphics.Point)3 IRangeComparator (org.eclipse.compare.rangedifferencer.IRangeComparator)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)1 RevisionRange (org.eclipse.jface.text.revisions.RevisionRange)1 DocEquivalenceComparator (org.eclipse.ui.internal.texteditor.quickdiff.compare.equivalence.DocEquivalenceComparator)1 DocumentEquivalenceClass (org.eclipse.ui.internal.texteditor.quickdiff.compare.equivalence.DocumentEquivalenceClass)1