boolean (@NotNull final TextRange rangeInsideHost, @NotNull final StringBuilder outChars) { for (Pair<TextRange, String> fragment : myHost.getDecodedFragments()) { final TextRange encodedTextRange = fragment.getFirst(); final TextRange intersection = encodedTextRange.intersection(rangeInsideHost); if (intersection != null && !intersection.isEmpty()) { final String value = fragment.getSecond(); final String intersectedValue; if (value.codePointCount(0, value.length()) == 1 || value.length() == intersection.getLength()) { intersectedValue = value; } else { final int start = Math.max(0, rangeInsideHost.getStartOffset() - encodedTextRange.getStartOffset()); final int end = Math.min(value.length(), start + intersection.getLength()); intersectedValue = value.substring(start, end); } outChars.append(intersectedValue); } } return true; }