void (final Block block) { final Document document = block.editor.getDocument(); final CharSequence chars = document.getCharsSequence(); final IndentData minIndent = computeMinIndent(block.editor, block.psiFile, block.startLine, block.endLine); final CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getIndentOptions(block.psiFile); DocumentUtil.executeInBulk( document, block.endLine - block.startLine > Registry.intValue("comment.by.line.bulk.lines.trigger"), () -> { for (int line = block.endLine; line >= block.startLine; line--) { int lineStart = document.getLineStartOffset(line); int offset = lineStart; final StringBuilder buffer = new StringBuilder(); while (true) { IndentData indent = IndentData.createFrom(buffer, 0, buffer.length(), indentOptions.TAB_SIZE); if (indent.getTotalSpaces() >= minIndent.getTotalSpaces()) break; char c = chars.charAt(offset); if (c != ' ' && c != '\t') { String newSpace = minIndent.createIndentInfo().generateNewWhiteSpace(indentOptions); document.replaceString(lineStart, offset, newSpace); offset = lineStart + newSpace.length(); break; } buffer.append(c); offset++; } commentLine(block, line, offset); } }); }