void (@NotNull String rawPreviewText) { myRanges.clear(); StringBuilder output = new StringBuilder(); int shift = 0; int searchOffset = 0; while (searchOffset < rawPreviewText.length()) { int rawBoldStart = rawPreviewText.indexOf(BOLD_START_MARKER, searchOffset); if (rawBoldStart >= 0) { output.append(rawPreviewText, searchOffset, rawBoldStart); int boldStart = rawBoldStart - shift; myRanges.add(new RangeHighlightingData(searchOffset - shift, boldStart, false)); searchOffset = rawBoldStart + BOLD_START_MARKER.length(); shift += BOLD_START_MARKER.length(); int rawBoldEnd = rawPreviewText.indexOf(BOLD_END_MARKER, searchOffset); if (rawBoldEnd < 0) rawBoldEnd = rawPreviewText.length(); output.append(rawPreviewText, searchOffset, rawBoldEnd); int boldEnd = rawBoldEnd - shift; searchOffset = rawBoldEnd + BOLD_END_MARKER.length(); shift += BOLD_END_MARKER.length(); myRanges.add(new RangeHighlightingData(boldStart, boldEnd, true)); } else { myRanges.add(new RangeHighlightingData(searchOffset - shift, rawPreviewText.length() - shift, false)); output.append(rawPreviewText, searchOffset, rawPreviewText.length()); break; } } myText = output.toString(); }