boolean () { FoldingModelImpl foldingModel = myEditor.getFoldingModel(); FoldRegion[] topLevelRegions = foldingModel.fetchTopLevel(); if (topLevelRegions == null) { return false; } int caretOffset = myEditor.getCaretModel().getOffset(); int idx = foldingModel.getLastCollapsedRegionBefore(caretOffset); if (idx >= 0) { FoldRegion region = topLevelRegions[idx]; if (region instanceof CustomFoldRegion && region.getEndOffset() == caretOffset) { return true; } } if (idx + 1 < topLevelRegions.length) { FoldRegion region = topLevelRegions[idx + 1]; return region instanceof CustomFoldRegion && region.getStartOffset() <= caretOffset; } return false; }