int (int minOffset, int maxOffset, boolean preferMinOffset) { if (canBreakBeforeOrAfterCodePoint(Character.codePointAt(myText, maxOffset))) return maxOffset; for (int i = 0, offset = maxOffset; i < BASIC_LOOK_BACK_LENGTH && offset >= minOffset; i++) { int prevOffset = Character.offsetByCodePoints(myText, offset, -1); if (canBreakBeforeOrAfterCodePoint(Character.codePointAt(myText, prevOffset))) return offset; //noinspection AssignmentToForLoopParameter offset = prevOffset; } if (myLineWrapPositionStrategy == null) { myLineWrapPositionStrategy = LanguageLineWrapPositionStrategy.INSTANCE.forEditor(myEditor); } int wrapOffset = myLineWrapPositionStrategy.calculateWrapPosition(myDocument, myEditor.getProject(), minOffset - 1, maxOffset + 1, maxOffset + 1, false, true); if (wrapOffset < 0) return preferMinOffset ? minOffset : maxOffset; if (wrapOffset < minOffset) return minOffset; if (wrapOffset > maxOffset) return maxOffset; if (DocumentUtil.isInsideSurrogatePair(myDocument, wrapOffset)) return wrapOffset - 1; return wrapOffset; }