int (int nextWrapOffset) { while (logicalLine < myDocument.getLineCount()) { int lineStartOffset = myDocument.getLineStartOffset(logicalLine); if (lineStartOffset > nextWrapOffset) return nextWrapOffset; logicalLine++; if (!isCollapsed(lineStartOffset)) return lineStartOffset; } return nextWrapOffset; }