private static @NotNull String indentText(@NotNull String text, @NotNull String curLineIndent, boolean shouldInsertIndentInTheEnd) {
    List<String> lines = LineTokenizer.tokenizeIntoList(text, false, false);
    if (lines.isEmpty()) {
      // Such situation sometimes happens but I don't know how it is possible
      return text;
    }
    int minIndent = calculateMinBlockIndent(lines);
    String firstLine = lines.iterator().next();
    if (lines.size() == 1) {
      return firstLine;
    }
    String suffixIndent;
    if (shouldInsertIndentInTheEnd && isEmptyLine(lines.get(lines.size() - 1))) {
      suffixIndent = curLineIndent;
    }
    else {
      suffixIndent = "";
    }
    return firstLine.substring(YAMLTextUtil.getStartIndentSize(firstLine)) + "\n" +
           lines.stream().skip(1).map(line -> {
             // remove common indent and add needed indent
             if (!isEmptyLine(line)) {
               return curLineIndent + line.substring(minIndent);
             }
             else {
               // do not indent empty lines at all
               return "";
             }
           }).reduce((left, right) -> left + "\n" + right).orElse("")
           + suffixIndent;
  }
private static @NotNull String indentText(@NotNull String text, @NotNull String curLineIndent, boolean shouldInsertIndentInTheEnd)