/** * 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; }