void (IntList indices) { List<TextRange> rangesToRemove = new ArrayList<>(); for (int i = 0; i < indices.size(); i++) { int index = indices.getInt(i); rangesToRemove.add(TextRange.create(mySegments.getSegmentStart(index), mySegments.getSegmentEnd(index))); } rangesToRemove.sort((o1, o2) -> { int startDiff = o2.getStartOffset() - o1.getStartOffset(); return startDiff != 0 ? startDiff : o2.getEndOffset() - o1.getEndOffset(); }); DocumentUtil.executeInBulk(myDocument, () -> { if (isDisposed()) { return; } for (TextRange range : rangesToRemove) { myDocument.deleteString(range.getStartOffset(), range.getEndOffset()); } }); }