void (@NotNull List<TemplateDocumentChange> changes) { if (isDisposed() || changes.isEmpty()) { return; } if (changes.size() > 1) { ContainerUtil.sort(changes, (o1, o2) -> { int startDiff = o2.startOffset - o1.startOffset; return startDiff != 0 ? startDiff : o2.segmentNumber - o1.segmentNumber; }); } DocumentUtil.executeInBulk(getDocument(), () -> { for (TemplateDocumentChange change : changes) { replaceString(change.newValue, change.startOffset, change.endOffset, change.segmentNumber); } }); }