private static void tryAdding(@NotNull Int2ObjectMap<DisplayedFoldingAnchor> resultsMap,
                                @NotNull FoldRegion region,
                                int visualLine,
                                int visualHeight,
                                @NotNull DisplayedFoldingAnchor.Type type,
                                @NotNull List<FoldRegion> activeRegions) {
    DisplayedFoldingAnchor prev = resultsMap.get(visualLine);
    if (prev != null && !prev.type.singleLine) {
      if (type.singleLine) {
        // show single-line marks only if there are no other marks on the same line
        return;
      }
      if (region.getGroup() != null && region.getGroup() == prev.foldRegion.getGroup() &&
          type != DisplayedFoldingAnchor.Type.COLLAPSED && type != prev.type) {
        // when top/bottom marks for regions from the same group overlap, don't show them at all
        resultsMap.remove(visualLine);
        return;
      }
      if (activeRegions.contains(prev.foldRegion)) {
        return;
      }
      if (!activeRegions.contains(region) && prev.foldRegionVisualLines < visualHeight) {
        return;
      }
    }
    resultsMap.put(visualLine, new DisplayedFoldingAnchor(region, visualLine, visualHeight, type));
  }
private static void tryAdding(@NotNull Int2ObjectMap<DisplayedFoldingAnchor> resultsMap,
                                @NotNull FoldRegion region,
                                int visualLine,
                                int visualHeight,
                                @NotNull DisplayedFoldingAnchor.Type type,
                                @NotNull List<FoldRegion> activeRegions)