int (final Point p) { DocumentEx document = myEditor.getDocument(); int line = EditorUtil.yPositionToLogicalLine(myEditor, p); if (!DocumentUtil.isValidLine(line, document)) return -1; int startOffset = document.getLineStartOffset(line); final FoldRegion region = myEditor.getFoldingModel().getCollapsedRegionAtOffset(startOffset); if (region != null) { return document.getLineNumber(region.getEndOffset()); } return line; }