void (final SimpleColoredComponent simpleColoredComponent, final @Nls String text, Iterable<? extends TextRange> colored, final SimpleTextAttributes plain, final SimpleTextAttributes highlighted) { final List<Pair<String, Integer>> searchTerms = new ArrayList<>(); for (TextRange fragment : colored) { searchTerms.add(Pair.create(fragment.substring(text), fragment.getStartOffset())); } int lastOffset = 0; for (Pair<String, Integer> pair : searchTerms) { if (pair.second > lastOffset) { simpleColoredComponent.append(text.substring(lastOffset, pair.second), plain); } simpleColoredComponent.append(text.substring(pair.second, pair.second + pair.first.length()), highlighted); lastOffset = pair.second + pair.first.length(); } if (lastOffset < text.length()) { simpleColoredComponent.append(text.substring(lastOffset), plain); } }