/** * Returns whether the marked region of this viewer is empty. * * @return <code>true</code> if the marked region of this viewer is empty, otherwise <code>false</code> * @since 2.0 */ private boolean isMarkedRegionEmpty() { return fTextWidget == null || fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null; }
/** * Returns whether the marked region of this viewer is empty. * * @return <code>true</code> if the marked region of this viewer is empty, otherwise <code>false</code> * @since 2.0 */ private boolean isMarkedRegionEmpty() { return fTextWidget == null || fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null; }
/** * Same as {@link #modelRange2WidgetRange(IRegion)} just for a {@link org.eclipse.jface.text.Position}. * * @param modelPosition the position describing a range in the viewer's document * @return a region describing a range in the viewer's widget * @since 2.1 */ protected IRegion modelRange2WidgetRange(Position modelPosition) { return modelRange2WidgetRange(new Region(modelPosition.getOffset(), modelPosition.getLength())); }
/** * Same as {@link #modelRange2WidgetRange(IRegion)} just for a {@link org.eclipse.jface.text.Position}. * * @param modelPosition the position describing a range in the viewer's document * @return a region describing a range in the viewer's widget * @since 2.1 */ protected IRegion modelRange2WidgetRange(Position modelPosition) { return modelRange2WidgetRange(new Region(modelPosition.getOffset(), modelPosition.getLength())); }
IRegion region= modelRange2WidgetRange(presentation.getCoverage()); if (region == null) return;
IRegion region= modelRange2WidgetRange(presentation.getCoverage()); if (region == null) return;
/** * Translates a style range given relative to the viewer's document into style * ranges relative to the viewer's widget or <code>null</code>. * * @param range the style range in the coordinates of the viewer's document * @return the style range in the coordinates of the viewer's widget or <code>null</code> * @since 2.1 */ protected StyleRange modelStyleRange2WidgetStyleRange(StyleRange range) { IRegion region= modelRange2WidgetRange(new Region(range.start, range.length)); if (region != null) { StyleRange result= (StyleRange) range.clone(); result.start= region.getOffset(); result.length= region.getLength(); return result; } return null; }
/** * Translates a style range given relative to the viewer's document into style * ranges relative to the viewer's widget or <code>null</code>. * * @param range the style range in the coordinates of the viewer's document * @return the style range in the coordinates of the viewer's widget or <code>null</code> * @since 2.1 */ protected StyleRange modelStyleRange2WidgetStyleRange(StyleRange range) { IRegion region= modelRange2WidgetRange(new Region(range.start, range.length)); if (region != null) { StyleRange result= (StyleRange) range.clone(); result.start= region.getOffset(); result.length= region.getLength(); return result; } return null; }
return null; IRegion region= ((TextViewer)fInput.fViewer).modelRange2WidgetRange(new Region(pos.offset, pos.length)); if (region == null) return null;
return null; IRegion region= ((TextViewer)fInput.fViewer).modelRange2WidgetRange(new Region(pos.offset, pos.length)); if (region == null) return null;
return null; IRegion region= ((TextViewer)fInput.fViewer).modelRange2WidgetRange(new Region(pos.offset, pos.length)); if (region == null) return null;
private IRegion modelRange2WidgetRange(IRegion region) { if (fEditorViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fEditorViewer; return extension.modelRange2WidgetRange(region); } if (fEditorViewer instanceof TextViewer) { return ((TextViewer) fEditorViewer).modelRange2WidgetRange(region); } IRegion visibleRegion = fEditorViewer.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); }
/** * Invalidates the given range of the text presentation. * * @param offset the offset of the range to be invalidated * @param length the length of the range to be invalidated * @since 2.1 */ @Override public final void invalidateTextPresentation(int offset, int length) { if (fVisibleDocument != null) { IRegion widgetRange= modelRange2WidgetRange(new Region(offset, length)); if (widgetRange != null) { fWidgetCommand.event= null; fWidgetCommand.start= widgetRange.getOffset(); fWidgetCommand.length= widgetRange.getLength(); try { fWidgetCommand.text= fVisibleDocument.get(widgetRange.getOffset(), widgetRange.getLength()); updateTextListeners(fWidgetCommand); } catch (BadLocationException x) { // can not happen because of previous checking } } } }
/** * Invalidates the given range of the text presentation. * * @param offset the offset of the range to be invalidated * @param length the length of the range to be invalidated * @since 2.1 */ @Override public final void invalidateTextPresentation(int offset, int length) { if (fVisibleDocument != null) { IRegion widgetRange= modelRange2WidgetRange(new Region(offset, length)); if (widgetRange != null) { fWidgetCommand.event= null; fWidgetCommand.start= widgetRange.getOffset(); fWidgetCommand.length= widgetRange.getLength(); try { fWidgetCommand.text= fVisibleDocument.get(widgetRange.getOffset(), widgetRange.getLength()); updateTextListeners(fWidgetCommand); } catch (BadLocationException x) { // can not happen because of previous checking } } } }
/** * Paints the highlighting of this range. */ private void paint() { IRegion widgetRegion= modelRange2WidgetRange(fPosition); int offset= widgetRegion.getOffset(); int length= widgetRegion.getLength(); int count= fTextWidget.getCharCount(); if (offset + length >= count) { length= count - offset; // clip Point upperLeft= fTextWidget.getLocationAtOffset(offset); Point lowerRight= fTextWidget.getLocationAtOffset(offset + length); int width= fTextWidget.getClientArea().width; int height= fTextWidget.getLineHeight(offset + length) + lowerRight.y - upperLeft.y; fTextWidget.redraw(upperLeft.x, upperLeft.y, width, height, false); } fTextWidget.redrawRange(offset, length, true); }
/** * Paints the highlighting of this range. */ private void paint() { IRegion widgetRegion= modelRange2WidgetRange(fPosition); int offset= widgetRegion.getOffset(); int length= widgetRegion.getLength(); int count= fTextWidget.getCharCount(); if (offset + length >= count) { length= count - offset; // clip Point upperLeft= fTextWidget.getLocationAtOffset(offset); Point lowerRight= fTextWidget.getLocationAtOffset(offset + length); int width= fTextWidget.getClientArea().width; int height= fTextWidget.getLineHeight(offset + length) + lowerRight.y - upperLeft.y; fTextWidget.redraw(upperLeft.x, upperLeft.y, width, height, false); } fTextWidget.redrawRange(offset, length, true); }
/** * Copies/cuts the marked region. * * @param delete <code>true</code> if the region should be deleted rather than copied. * @since 2.0 */ protected void copyMarkedRegion(boolean delete) { if (fTextWidget == null) return; if (fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null) return; int widgetMarkOffset= modelOffset2WidgetOffset(fMarkPosition.offset); Point selection= fTextWidget.getSelection(); if (selection.x <= widgetMarkOffset) fTextWidget.setSelection(selection.x, widgetMarkOffset); else fTextWidget.setSelection(widgetMarkOffset, selection.x); if (delete) { wrapCompoundChange(new Runnable() { @Override public void run() { fTextWidget.cut(); } }); } else { fTextWidget.copy(); fTextWidget.setSelection(selection.x); // restore old cursor position } }
/** * Copies/cuts the marked region. * * @param delete <code>true</code> if the region should be deleted rather than copied. * @since 2.0 */ protected void copyMarkedRegion(boolean delete) { if (fTextWidget == null) return; if (fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null) return; int widgetMarkOffset= modelOffset2WidgetOffset(fMarkPosition.offset); Point selection= fTextWidget.getSelection(); if (selection.x <= widgetMarkOffset) fTextWidget.setSelection(selection.x, widgetMarkOffset); else fTextWidget.setSelection(widgetMarkOffset, selection.x); if (delete) { wrapCompoundChange(() -> fTextWidget.cut()); } else { fTextWidget.copy(); fTextWidget.setSelection(selection.x); // restore old cursor position } }
/** * Similar to {@link #modelRange2WidgetRange(IRegion)}, but more forgiving: * if <code>modelRange</code> describes a region entirely hidden in the * image, then this method returns the zero-length region at the offset of * the folded region. * * @param modelRange the model range * @return the corresponding widget range, or <code>null</code> * @since 3.1 */ protected IRegion modelRange2ClosestWidgetRange(IRegion modelRange) { if (!(fInformationMapping instanceof IDocumentInformationMappingExtension2)) return modelRange2WidgetRange(modelRange); try { if (modelRange.getLength() < 0) { Region reversed= new Region(modelRange.getOffset() + modelRange.getLength(), -modelRange.getLength()); IRegion result= ((IDocumentInformationMappingExtension2) fInformationMapping).toClosestImageRegion(reversed); if (result != null) return new Region(result.getOffset() + result.getLength(), -result.getLength()); } return ((IDocumentInformationMappingExtension2) fInformationMapping).toClosestImageRegion(modelRange); } catch (BadLocationException x) { } return null; }
/** * Similar to {@link #modelRange2WidgetRange(IRegion)}, but more forgiving: * if <code>modelRange</code> describes a region entirely hidden in the * image, then this method returns the zero-length region at the offset of * the folded region. * * @param modelRange the model range * @return the corresponding widget range, or <code>null</code> * @since 3.1 */ protected IRegion modelRange2ClosestWidgetRange(IRegion modelRange) { if (!(fInformationMapping instanceof IDocumentInformationMappingExtension2)) return modelRange2WidgetRange(modelRange); try { if (modelRange.getLength() < 0) { Region reversed= new Region(modelRange.getOffset() + modelRange.getLength(), -modelRange.getLength()); IRegion result= ((IDocumentInformationMappingExtension2) fInformationMapping).toClosestImageRegion(reversed); if (result != null) return new Region(result.getOffset() + result.getLength(), -result.getLength()); } return ((IDocumentInformationMappingExtension2) fInformationMapping).toClosestImageRegion(modelRange); } catch (BadLocationException x) { } return null; }