PlainText (PlainText plainText, int commonIndent) { if (commonIndent <= 0) return plainText; String content = plainText.content(); int curIndent = 0; while (curIndent < commonIndent && curIndent < content.length() && content.charAt(curIndent) != '\n' && Character.isWhitespace(content.charAt(curIndent))) { curIndent++; } if (curIndent == 0) return plainText; content = content.substring(curIndent); return new PlainText(TextRange.create(plainText.range().getStartOffset() + curIndent, plainText.range().getEndOffset()), content); }