RangeHighlighter (int startOffset, int endOffset, TextAttributes attributes) { MarkupModelEx markupModel = (MarkupModelEx)mySearchResults.getEditor().getMarkupModel(); RangeHighlighter[] existing = new RangeHighlighter[1]; markupModel.processRangeHighlightersOverlappingWith(startOffset, startOffset, highlighter -> { if (highlighter.getUserData(SEARCH_MARKER) != null && highlighter.getStartOffset() == startOffset && highlighter.getEndOffset() == endOffset && Objects.equals(highlighter.getTextAttributes(mySearchResults.getEditor().getColorsScheme()), attributes)) { existing[0] = highlighter; return false; } return true; }); return existing[0]; }