LogicalPosition (VisualPosition visiblePos) { ThreadingAssertions.assertEventDispatchThread(); 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) { LogicalPosition logFoldEnd = offsetToLogicalPosition(lastCollapsedBefore.getEndOffset()); VisualPosition visFoldEnd = logicalToVisualPosition(logFoldEnd); line = logFoldEnd.line + (visiblePos.line - visFoldEnd.line); if (visFoldEnd.line == visiblePos.line) { if (visiblePos.column >= visFoldEnd.column) { column = logFoldEnd.column + (visiblePos.column - visFoldEnd.column); } else { return offsetToLogicalPosition(lastCollapsedBefore.getStartOffset()); } } } if (column < 0) column = 0; return new LogicalPosition(line, column); }