LineColumn (@NotNull CharSequence text, int offset) { int curLine = 0; int curLineStart = 0; int curOffset = 0; while (curOffset < offset) { if (curOffset == text.length()) return null; char c = text.charAt(curOffset); if (c == '\n') { curLine++; curLineStart = curOffset + 1; } else if (c == '\r') { curLine++; if (curOffset < text.length() - 1 && text.charAt(curOffset + 1) == '\n') { curOffset++; } curLineStart = curOffset + 1; } curOffset++; } return LineColumn.of(curLine, offset - curLineStart); }