LogicalPosition (@NotNull VisualPosition visiblePos, boolean softWrapAware) { if (myUseNewRendering) return myView.visualToLogicalPosition(visiblePos); assertReadAccess(); if (softWrapAware) { return mySoftWrapModel.visualToLogicalPosition(visiblePos); } if (!myFoldingModel.isFoldingEnabled()) return new LogicalPosition(visiblePos.line, visiblePos.column); int line = visiblePos.line; int column = visiblePos.column; FoldRegion lastCollapsedBefore = getLastCollapsedBeforePosition(visiblePos); if (lastCollapsedBefore != null) { int logFoldEndLine = offsetToLogicalLine(lastCollapsedBefore.getEndOffset()); int visFoldEndLine = logicalToVisualLine(logFoldEndLine); line = logFoldEndLine + visiblePos.line - visFoldEndLine; if (visFoldEndLine == visiblePos.line) { LogicalPosition logFoldEnd = offsetToLogicalPosition(lastCollapsedBefore.getEndOffset(), false); VisualPosition visFoldEnd = logicalToVisualPosition(logFoldEnd, false); if (visiblePos.column >= visFoldEnd.column) { column = logFoldEnd.column + visiblePos.column - visFoldEnd.column; } else { return offsetToLogicalPosition(lastCollapsedBefore.getStartOffset(), false); } } } if (column < 0) column = 0; return new LogicalPosition(line, column); }