void (@NotNull PsiFile file, Document document, List<? extends FormatTextRange> textRanges) { RangeMarker[] markers = new RangeMarker[textRanges.size()]; int i = 0; for (FormatTextRange range : textRanges) { TextRange textRange = range.getTextRange(); int start = textRange.getStartOffset(); int end = textRange.getEndOffset(); if (start >= 0 && end > start && end <= document.getTextLength()) { markers[i] = document.createRangeMarker(textRange); markers[i].setGreedyToLeft(true); markers[i].setGreedyToRight(true); i++; } } PostprocessReformattingAspect component = PostprocessReformattingAspect.getInstance(file.getProject()); FORMATTING_CANCELLED_FLAG.set(false); component.doPostponedFormatting(file.getViewProvider()); i = 0; for (FormatTextRange range : textRanges) { RangeMarker marker = markers[i]; if (marker != null) { range.setTextRange(marker.getTextRange()); marker.dispose(); } i++; } }