private static boolean makeVisible(SortedSet<PreviewEditorFoldingRegion> foldingRegions, Segment toShowRange, Document document) {
    if (toShowRange == null) return false;
    boolean isUpdated = false;
    final int startLine = Math.max(0, document.getLineNumber(toShowRange.getStartOffset()) - SHOWN_LINES_COUNT);
    final int endLine = Math.min(document.getLineCount(), document.getLineNumber(toShowRange.getEndOffset()) + SHOWN_LINES_COUNT + 1);
    for (PreviewEditorFoldingRegion range : new ArrayList<>(foldingRegions)) {
      final boolean startInRegion = range.contain(startLine);
      final boolean endInRegion = range.contain(endLine);
      if (startInRegion && endInRegion) {
        foldingRegions.remove(range);
        if (range.getStartLine() != startLine) {
          foldingRegions.add(new PreviewEditorFoldingRegion(range.getStartLine(), startLine));
        }
        if (endLine != range.getEndLine()) {
          foldingRegions.add(new PreviewEditorFoldingRegion(endLine, range.getEndLine()));
        }
        return true;
      }
      if (startInRegion) {
        foldingRegions.remove(range);
        if (range.getStartLine() != startLine) {
          foldingRegions.add(new PreviewEditorFoldingRegion(range.getStartLine(), startLine));
        }
        isUpdated = true;
      }
      if (endInRegion) {
        foldingRegions.remove(range);
        if (endLine != range.getEndLine()) {
          foldingRegions.add(new PreviewEditorFoldingRegion(endLine, range.getEndLine()));
        }
        return true;
      }
    }
    return isUpdated;
  }
private static boolean makeVisible(SortedSet<PreviewEditorFoldingRegion> foldingRegions, Segment toShowRange, Document document)