VisualPosition (LogicalPosition logicalPos) { ThreadingAssertions.assertEventDispatchThread(); if (!myFoldingModel.isFoldingEnabled()) return new VisualPosition(logicalPos.line, logicalPos.column); int offset = logicalPositionToOffset(logicalPos); FoldRegion outermostCollapsed = myFoldingModel.getCollapsedRegionAtOffset(offset); if (outermostCollapsed != null && offset > outermostCollapsed.getStartOffset()) { if (offset < getDocument().getTextLength() - 1) { offset = outermostCollapsed.getStartOffset(); LogicalPosition foldStart = offsetToLogicalPosition(offset); return logicalToVisualPosition(foldStart); } else { offset = outermostCollapsed.getEndOffset() + 3; } } int line = logicalPos.line; int column = logicalPos.column; line -= myFoldingModel.getFoldedLinesCountBefore(offset); FoldRegion[] toplevel = myFoldingModel.fetchTopLevel(); for (int idx = myFoldingModel.getLastTopLevelIndexBefore(offset); idx >= 0; idx--) { FoldRegion region = toplevel[idx]; if (region.isValid()) { if (region.getDocument().getLineNumber(region.getEndOffset()) == logicalPos.line && region.getEndOffset() <= offset) { LogicalPosition foldStart = offsetToLogicalPosition(region.getStartOffset()); LogicalPosition foldEnd = offsetToLogicalPosition(region.getEndOffset()); column += foldStart.column + region.getPlaceholderText().length() - foldEnd.column; offset = region.getStartOffset(); logicalPos = foldStart; } else { break; } } } LOG.assertTrue(line >= 0); return new VisualPosition(line, Math.max(0, column)); }