int (@NotNull Editor editor, int startOffset, boolean stopAtInvisibleFoldRegions) { return ReadAction.compute(() -> { int offset = startOffset; while (true) { offset = getLineEndOffset(offset, editor.getDocument()); FoldRegion foldRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(offset); if (foldRegion == null || stopAtInvisibleFoldRegions && foldRegion.getPlaceholderText().isEmpty() || foldRegion.getEndOffset() <= offset) { break; } offset = foldRegion.getEndOffset(); } return offset; }); }