/** * Computes the document offset underlying the given text widget coordinates. * This method uses a linear search as it cannot make any assumption about * how the document is actually presented in the widget. (Covers cases such * as bidirectional text.) * * @param x the horizontal coordinate inside the text widget * @param y the vertical coordinate inside the text widget * @return the document offset corresponding to the given point */ private int computeOffsetAtLocation(int x, int y) { try { StyledText styledText= fTextViewer.getTextWidget(); int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y)); Point p= styledText.getLocationAtOffset(widgetOffset); if (p.x > x) widgetOffset--; if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } return widgetOffset + fTextViewer._getVisibleRegionOffset(); } catch (IllegalArgumentException e) { return -1; } }
/** * Computes the document offset underlying the given text widget coordinates. * This method uses a linear search as it cannot make any assumption about * how the document is actually presented in the widget. (Covers cases such * as bidirectional text.) * * @param x the horizontal coordinate inside the text widget * @param y the vertical coordinate inside the text widget * @return the document offset corresponding to the given point */ private int computeOffsetAtLocation(int x, int y) { try { StyledText styledText= fTextViewer.getTextWidget(); int widgetOffset= styledText.getOffsetAtPoint(new Point(x, y)); if (widgetOffset == -1) { return -1; } Point p= styledText.getLocationAtOffset(widgetOffset); if (p.x > x) { widgetOffset--; } if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } return widgetOffset + fTextViewer._getVisibleRegionOffset(); } catch (IllegalArgumentException e) { return -1; } }