int (int startOffset) { if (myUseOnlyFullLineHighlighters || myFoldingModel == null) { return myEnd; } int end = myEnd; FoldRegion[] topLevelCollapsed = myFoldingModel.fetchTopLevel(); if (topLevelCollapsed != null) { if (myReverseIteration) { for (int i = myFoldingModel.getLastCollapsedRegionBefore(startOffset); i >= 0 && i < topLevelCollapsed.length; i--) { FoldRegion range = topLevelCollapsed[i]; if (!range.isValid()) continue; int rangeEnd = range.getEndOffset(); if (rangeEnd < startOffset) { if (rangeEnd > end) { end = rangeEnd; } else { break; } } } } else { for (int i = myFoldingModel.getLastCollapsedRegionBefore(startOffset) + 1; i >= 0 && i < topLevelCollapsed.length; i++) { FoldRegion range = topLevelCollapsed[i]; if (!range.isValid()) continue; int rangeEnd = range.getStartOffset(); if (rangeEnd > startOffset) { if (rangeEnd < end) { end = rangeEnd; } else { break; } } } } } return end; }