LineCol (@NotNull Document document, int offset) { if (offset < document.getTextLength()) { int line = document.getLineNumber(offset); int column = offset - document.getLineStartOffset(line); return new LineCol(line, column); } else { int line = Math.max(0, document.getLineCount() - 1); int column = document.getLineEndOffset(line) - document.getLineStartOffset(line); return new LineCol(line, column); } }