@Override public ILineRegion regionForLineAtOffset(int offset) { String text = getText(); if (offset < 0 || offset > text.length()) return null; int start = text.lastIndexOf('\n', offset) + 1; if (start < 0) start = 0; int end = text.indexOf('\n', offset + 1); if (end > 0) { if (text.charAt(end - 1) == '\r') end = end - 1; } else end = text.length(); return new LineRegion(this, start, end - start); }
@Override public ILineRegion getNextLine() { ITextRegionAccess access = getTextRegionAccess(); int start = getEndOffset() + 1; String text = access.regionForDocument().getText(); while (true) { if (start >= text.length()) return null; char c = text.charAt(start); if (c == '\n' || c == '\r') start++; else break; } int end = text.indexOf('\n', start); if (end > 0) { if (text.charAt(end - 1) == '\r') end = end - 1; } else end = text.length(); return new LineRegion(access, start, end - start); }
@Override public ILineRegion getPreviousLine() { ITextRegionAccess access = getTextRegionAccess(); int end = getOffset() - 1; String text = access.regionForDocument().getText(); while (true) { if (end < 0) return null; char c = text.charAt(end); if (c == '\n' || c == '\r') end--; else break; } int start = text.lastIndexOf('\n', end); if (start < 0) start = 0; return new LineRegion(access, start, end - start); }
private ITextSegment getRegionForLines(ITextRegionAccess regions, int offset, int lines) { ILineRegion firstLine = regions.regionForLineAtOffset(offset); ILineRegion lastLine = firstLine; for (int i = 1; i < lines; i++) { ILineRegion next = lastLine.getNextLine(); if (next != null) { lastLine = next; } else { break; } } int firstLineOffset = firstLine.getOffset(); ITextSegment region = regions.regionForOffset(firstLineOffset, (lastLine.getEndOffset() - firstLineOffset) + 1); return region; }
public ITextSegment getFrame() { if (this.frame != null) return this.frame; ITextRegionAccess access = getTextRegionAccess(); if (access != null) { ITextSegment impactRegion = TextRegions.merge(this.items); List<ILineRegion> expandToLines = TextRegions.expandToLines(impactRegion, getLeadingLines(), getTrailingLines()); return TextRegions.merge(expandToLines); } return null; }
public ITextSegment getFrame() { if (this.frame != null) return this.frame; ITextRegionAccess access = getTextRegionAccess(); if (access != null) { List<ITextSegment> segments = Lists.newArrayList(); for (Item item : items) segments.add(item.getRegion()); ITextSegment impactRegion = merge(segments); List<ILineRegion> expandToLines = expandToLines(impactRegion, getLeadingLines(), getTrailingLines()); return merge(expandToLines); } return null; }
@Override public List<ILineRegion> getLineRegions() { ILineRegion current = getTextRegionAccess().regionForLineAtOffset(getOffset()); List<ILineRegion> result = Lists.newArrayList(); int endOffset = getEndOffset(); while (current != null) { result.add(current); if (current.getEndOffset() >= endOffset) return result; current = current.getNextLine(); if (current == null || current.getOffset() >= endOffset) return result; } return result; }