Search in sources :

Example 1 with ILineRange

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;
}
Also used : ILineRange(org.eclipse.jface.text.source.ILineRange) ArrayList(java.util.ArrayList) Range(org.eclipse.jface.internal.text.revisions.Range) ILineRange(org.eclipse.jface.text.source.ILineRange)

Example 2 with ILineRange

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);
}
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 3 with ILineRange

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();
}
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 4 with ILineRange

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;
}
Also used : ILineRange(org.eclipse.jface.text.source.ILineRange) ArrayList(java.util.ArrayList) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion)

Example 5 with ILineRange

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

Aggregations

ILineRange (org.eclipse.jface.text.source.ILineRange)10 LineRange (org.eclipse.jface.text.source.LineRange)5 Point (org.eclipse.swt.graphics.Point)4 IDocument (org.eclipse.jface.text.IDocument)3 ArrayList (java.util.ArrayList)2 Range (org.eclipse.jface.internal.text.revisions.Range)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IRegion (org.eclipse.jface.text.IRegion)2 IRangeComparator (org.eclipse.compare.rangedifferencer.IRangeComparator)1 ChangeRegion (org.eclipse.jface.internal.text.revisions.ChangeRegion)1 IInformationControlCreator (org.eclipse.jface.text.IInformationControlCreator)1 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)1 Region (org.eclipse.jface.text.Region)1 IInformationProvider (org.eclipse.jface.text.information.IInformationProvider)1 IInformationProviderExtension2 (org.eclipse.jface.text.information.IInformationProviderExtension2)1 Revision (org.eclipse.jface.text.revisions.Revision)1 RevisionRange (org.eclipse.jface.text.revisions.RevisionRange)1 IAnnotationHoverExtension (org.eclipse.jface.text.source.IAnnotationHoverExtension)1 Color (org.eclipse.swt.graphics.Color)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1