TextRange (@NotNull LineOffsets lineOffsets, int line1, int line2, boolean includeNewline) { if (line1 == line2) { int lineStartOffset = line1 < lineOffsets.getLineCount() ? lineOffsets.getLineStart(line1) : lineOffsets.getTextLength(); return new TextRange(lineStartOffset, lineStartOffset); } else { int startOffset = lineOffsets.getLineStart(line1); int endOffset = lineOffsets.getLineEnd(line2 - 1); if (includeNewline && endOffset < lineOffsets.getTextLength()) endOffset++; return new TextRange(startOffset, endOffset); } }