void () { final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel(); int[] starts = selectionModel.getBlockSelectionStarts(); int[] ends = selectionModel.getBlockSelectionEnds(); for (RangeHighlighter highlighter : myHighlighters) { if (!highlighter.isValid()) continue; boolean needsAdditionalHighlighting = false; TextRange cursor = mySearchResults.getCursor(); if (cursor == null || highlighter.getStartOffset() != cursor.getStartOffset() || highlighter.getEndOffset() != cursor.getEndOffset()) { for (int i = 0; i < starts.length; ++i) { TextRange selectionRange = new TextRange(starts[i], ends[i]); needsAdditionalHighlighting = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) && selectionRange.getEndOffset() != highlighter.getStartOffset() && highlighter.getEndOffset() != selectionRange.getStartOffset(); if (needsAdditionalHighlighting) break; } } RangeHighlighter inSelectionHighlighter = highlighter.getUserData(IN_SELECTION_KEY); if (inSelectionHighlighter != null) { if (!needsAdditionalHighlighting) { removeHighlighter(inSelectionHighlighter); highlighter.putUserData(IN_SELECTION_KEY, null); } } else if (needsAdditionalHighlighting) { RangeHighlighter additionalHighlighter = addHighlighter(highlighter.getStartOffset(), highlighter.getEndOffset(), myPresentation.getSelectionAttributes(), myPresentation.getDefaultLayer()); highlighter.putUserData(IN_SELECTION_KEY, additionalHighlighter); } } }