void (int startIndex, int endIndex) { Object2IntOpenHashMap<Mapper> mins = new Object2IntOpenHashMap<>(endIndex - startIndex); mins.defaultReturnValue(-1); Object2IntOpenHashMap<Mapper> maxs = new Object2IntOpenHashMap<>(endIndex - startIndex); maxs.defaultReturnValue(-1); for (int i = startIndex; i < endIndex; i++) { MappedRange range = myRanges[i]; if (range != null && range.range.isValid()) { Mapper mapper = range.mapper; int currentMin = mins.getOrDefault(mapper, Integer.MAX_VALUE); mins.put(mapper, Math.min(currentMin, range.range.getStartOffset())); int currentMax = maxs.getOrDefault(mapper, 0); maxs.put(mapper, Math.max(currentMax, range.range.getEndOffset())); } myRanges[i] = null; } for (Object2IntMap.Entry<Mapper> entry : maxs.object2IntEntrySet()) { Mapper mapper = entry.getKey(); int max = entry.getIntValue(); freezeHighlighter(mapper); int min = mins.getInt(mapper); mapper.doc.deleteString(min - mapper.mySeparator.length(), max); } removeRange(myRanges, startIndex, endIndex); super.remove(startIndex, endIndex); }