long (@NotNull DocumentEvent e, int intervalStart, boolean greedyRight, boolean stickyRight) { int offset = e.getOffset(); int oldLength = e.getOldLength(); int oldEnd = offset + oldLength; if (offset < intervalStart && intervalStart < oldEnd) { return -1; } if (offset == intervalStart && oldLength == 0) { if (greedyRight) { return TextRangeScalarUtil.toScalarRange(intervalStart, intervalStart + e.getNewLength()); } else if (stickyRight) { int off = intervalStart + e.getNewLength(); return TextRangeScalarUtil.toScalarRange(off, off); } } if (intervalStart > oldEnd || intervalStart == oldEnd && oldLength > 0) { int off = intervalStart + e.getNewLength() - oldLength; return TextRangeScalarUtil.toScalarRange(off, off); } return TextRangeScalarUtil.toScalarRange(intervalStart, intervalStart); }