@Override
  public @Nullable CustomFoldRegion addCustomLinesFolding(int startLine, int endLine, @NotNull CustomFoldRegionRenderer renderer) {
    assertIsDispatchThreadForEditor();
    if (!myIsBatchFoldingProcessing) {
      LOG.error("Fold regions must be added or removed inside batchFoldProcessing() only.");
      return null;
    }
    Document document = myEditor.getDocument();
    int maxLineNumber = Math.max(0, document.getLineCount() - 1);
    startLine = Math.max(0, Math.min(maxLineNumber, startLine));
    endLine = Math.max(startLine, Math.min(maxLineNumber, endLine));
    int startOffset = document.getLineStartOffset(startLine);
    int endOffset = document.getLineEndOffset(endLine);

    if (!isFoldingEnabled() || startOffset >= endOffset || !myFoldTree.checkIfValidToCreate(startOffset, endOffset, true, null)) {
      return null;
    }

    CustomFoldRegionImpl region = new CustomFoldRegionImpl(myEditor, startOffset, endOffset, renderer);
    myRegionTree.addInterval(region, startOffset, endOffset, false, false, false, 0);
    LOG.assertTrue(region.isValid());

    collapseFoldRegion(region, false);
    if (region.isExpanded()) { // caret inside region and 'do not collapse caret' flag is active
      region.putUserData(DO_NOT_NOTIFY, Boolean.TRUE);
      myRegionTree.removeInterval(region);
      return null;
    }
    onFoldRegionStateChange(region);

    LOG.assertTrue(region.isValid());
    return region;
  }
@Override
  public @Nullable CustomFoldRegion addCustomLinesFolding(int startLine, int endLine, @NotNull CustomFoldRegionRenderer renderer)