LogicalPosition (int offset) { int clamped = MathUtil.clamp(offset, 0, myDocument.getTextLength()); int line = myDocument.getLineNumber(clamped); int col = clamped - myDocument.getLineStartOffset(line); return new LogicalPosition(line, col); }