void (@NotNull SimpleColoredComponent coloredComponent, @Nullable Iterable<? extends TextRange> ranges, boolean selected) { Iterator<? extends TextRange> rangesIterator = ranges != null ? ranges.iterator() : null; if (rangesIterator == null || !rangesIterator.hasNext()) return; Color bg = UIUtil.getTreeBackground(selected, true); SimpleColoredComponent.ColoredIterator coloredIterator = coloredComponent.iterator(); TextRange range = rangesIterator.next(); main: while (coloredIterator.hasNext()) { coloredIterator.next(); int offset = coloredIterator.getOffset(); int endOffset = coloredIterator.getEndOffset(); if (!range.intersectsStrict(offset, endOffset)) continue; SimpleTextAttributes attributes = coloredIterator.getTextAttributes(); SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, attributes.getFgColor(), null, attributes.getStyle() | SimpleTextAttributes.STYLE_SEARCH_MATCH); do { if (range.getStartOffset() > offset) { offset = coloredIterator.split(range.getStartOffset() - offset, attributes); } if (range.getEndOffset() <= endOffset) { offset = coloredIterator.split(range.getEndOffset() - offset, highlighted); if (rangesIterator.hasNext()) { range = rangesIterator.next(); } else { break main; } } else { coloredIterator.split(endOffset - offset, highlighted); continue main; } } while (range.intersectsStrict(offset, endOffset)); } }