/**
  * Returns the location of the caret as offset in the source viewer's input document.
  *
  * @return the caret location
  */
 private int getModelCaret() {
   int widgetCaret = fViewer.getTextWidget().getCaretOffset();
   if (fViewer instanceof ITextViewerExtension5) {
     ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
     return extension.widgetOffset2ModelOffset(widgetCaret);
   }
   IRegion visible = fViewer.getVisibleRegion();
   return widgetCaret + visible.getOffset();
 }
Exemple #2
0
  private IRegion modelRange2WidgetRange(IRegion region) {
    ISourceViewer viewer = fEditor.getViewer();
    if (viewer instanceof ITextViewerExtension5) {
      ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
      return extension.modelRange2WidgetRange(region);
    }

    IRegion visibleRegion = viewer.getVisibleRegion();
    int start = region.getOffset() - visibleRegion.getOffset();
    int end = start + region.getLength();
    if (end > visibleRegion.getLength()) end = visibleRegion.getLength();

    return new Region(start, end - start);
  }
  /**
   * Internal draw request handler.
   *
   * @param gc Graphics context to update.
   */
  private final void handleDrawRequest(final GC gc) {
    if (mBracketPosition.isDeleted) {
      return;
    }

    int length = mBracketPosition.getLength();
    if (length < 1) {
      return;
    }

    int offset = mBracketPosition.getOffset();
    IRegion region = mSourceViewer.getVisibleRegion();

    if (region.getOffset() <= offset
        && region.getOffset() + region.getLength() >= offset + length) {
      offset -= region.getOffset();
      draw(gc, offset, 1);
    }
  }
  private Rectangle getLineRectangle(Position position) {
    if (position == null) {
      return null;
    }

    // if the position that is about to be drawn was deleted then we can't
    if (position.isDeleted()) {
      return null;
    }

    int widgetOffset = 0;
    if (fViewer instanceof ITextViewerExtension5) {

      ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
      widgetOffset = extension.modelOffset2WidgetOffset(position.getOffset());
      if (widgetOffset == -1) {
        return null;
      }
    } else {

      IRegion visible = fViewer.getVisibleRegion();
      widgetOffset = position.getOffset() - visible.getOffset();
      if (widgetOffset < 0 || visible.getLength() < widgetOffset) {
        return null;
      }
    }

    StyledText textWidget = fViewer.getTextWidget();
    // check for https://bugs.eclipse.org/bugs/show_bug.cgi?id=64898
    // this is a guard against the symptoms but not the actual solution
    if (0 <= widgetOffset && widgetOffset <= textWidget.getCharCount()) {
      Point upperLeft = textWidget.getLocationAtOffset(widgetOffset);
      int width = textWidget.getClientArea().width + textWidget.getHorizontalPixel();
      int height = textWidget.getLineHeight(widgetOffset);
      return new Rectangle(0, upperLeft.y, width, height);
    }

    return null;
  }