void (Document document) { List<Segment> markers = new ArrayList<>(); while (true) { String text = document.getText(); int spotStart = text.indexOf("<" + SPOT_MARKER + ">"); if (spotStart < 0) break; int spotEnd = text.indexOf("</" + SPOT_MARKER + ">", spotStart); if (spotEnd < 0) break; document.deleteString(spotEnd, spotEnd + SPOT_MARKER.length() + 3); document.deleteString(spotStart, spotStart + SPOT_MARKER.length() + 2); Segment spotMarker = new Segment() { @Override public int getStartOffset() { return spotStart; } @Override public int getEndOffset() { return spotEnd - SPOT_MARKER.length() - 2; } }; markers.add(spotMarker); } myRangeBlinker.resetMarkers(markers); if (!markers.isEmpty()) { myRangeBlinker.startBlinking(); } }