Search in sources :

Example 56 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project xtext-eclipse by eclipse.

the class MarkRegionTargetWithoutStatusline method isVisible.

/**
 * Tells whether the given offset is visible in the given text viewer.
 *
 * @param viewer
 *            the text viewer
 * @param offset
 *            the offset to check
 * @return <code>true</code> if the given offset is visible in the given text viewer
 */
protected boolean isVisible(ITextViewer viewer, int offset) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        return extension.modelOffset2WidgetOffset(offset) >= 0;
    }
    IRegion region = viewer.getVisibleRegion();
    int vOffset = region.getOffset();
    return (vOffset <= offset && offset <= vOffset + region.getLength());
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

Example 57 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project xtext-eclipse by eclipse.

the class TextViewerJoinLinesAction method adjustHighlightRange.

/**
 * Adjusts the highlight range so that at least the specified range
 * is highlighted.
 * <p>
 * Subclasses may re-implement this method.</p>
 *
 * @param offset the offset of the range which at least should be highlighted
 * @param length the length of the range which at least should be highlighted
 */
protected void adjustHighlightRange(ITextViewer viewer, int offset, int length) {
    if (viewer == null)
        return;
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        extension.exposeModelRange(new Region(offset, length));
    } else if (!isVisible(viewer, offset, length)) {
        viewer.resetVisibleRegion();
    }
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion)

Example 58 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project xtext-eclipse by eclipse.

the class TextViewerJoinLinesAction method isVisible.

protected boolean isVisible(ITextViewer viewer, int offset, int length) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        IRegion overlap = extension.modelRange2WidgetRange(new Region(offset, length));
        return overlap != null;
    }
    return viewer.overlapsWithVisibleRegion(offset, length);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)58 Point (org.eclipse.swt.graphics.Point)39 IRegion (org.eclipse.jface.text.IRegion)38 StyledText (org.eclipse.swt.custom.StyledText)23 Region (org.eclipse.jface.text.Region)17 BadLocationException (org.eclipse.jface.text.BadLocationException)14 IDocument (org.eclipse.jface.text.IDocument)14 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)7 ITextViewer (org.eclipse.jface.text.ITextViewer)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 Position (org.eclipse.jface.text.Position)5 GC (org.eclipse.swt.graphics.GC)5 StyleRange (org.eclipse.swt.custom.StyleRange)4 ITextViewerExtension2 (org.eclipse.jface.text.ITextViewerExtension2)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 ITextSelection (org.eclipse.jface.text.ITextSelection)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2 Display (org.eclipse.swt.widgets.Display)2 Entry (java.util.Map.Entry)1