TextRange (@NotNull TextRange range, @NotNull TextRange relative) { int start = Math.min(range.getEndOffset(), range.getStartOffset() + relative.getStartOffset()); int end = Math.min(range.getEndOffset(), range.getStartOffset() + relative.getEndOffset()); return new TextRange(start, end); }