Segment () { Document document = getDocument(); if (document == null) return null; Segment range = getUsageInfo().getNavigationRange(); if (range == null) { ProperTextRange rangeInElement = getUsageInfo().getRangeInElement(); range = myOffset < 0 ? new UnfairTextRange(-1,-1) : rangeInElement == null ? TextRange.from(myOffset,1) : rangeInElement.shiftRight(myOffset); } if (range.getEndOffset() >= document.getTextLength()) { int line = Math.max(0, Math.min(myLineNumber, document.getLineCount() - 1)); range = TextRange.from(document.getLineStartOffset(line),1); } return range; }