void (List<? extends RangeMarker> markers) { int size = markers.size(); if (size == 0) return; int[] spacesToAdd = getSpacesToAdd(markers); DocumentUtil.executeInBulk(myDoc, size > 100, () -> { for (int i = 0; i < size; i++) { myIndicator.checkCanceled(); myIndicator.setFraction(0.95 + 0.05 * i / size); RangeMarker marker = markers.get(i); if (!marker.isValid()) continue; CharSequence docText = myDoc.getCharsSequence(); int lineEndOffset = marker.getStartOffset(); int start = StringUtil.skipWhitespaceBackward(docText, lineEndOffset) - 1; int end = StringUtil.skipWhitespaceForward(docText, lineEndOffset); int replaceStart = start == lineEndOffset ? start : start + 1; if (myCaretRestoreOffset == CANNOT_JOIN) myCaretRestoreOffset = replaceStart; int spacesToCreate = spacesToAdd[i]; String spacing = StringUtil.repeatSymbol(' ', spacesToCreate); myDoc.replaceString(replaceStart, end, spacing); } }); myManager.commitDocument(myDoc); }