LogicalPosition (@NotNull LogicalPosition hPos) { assertValid(); DocumentEx hostDocument = myDelegate.getDocument(); int hLineEndOffset = hPos.line >= hostDocument.getLineCount() ? hostDocument.getTextLength() : hostDocument.getLineEndOffset(hPos.line); LogicalPosition hLineEndPos = myDelegate.offsetToLogicalPosition(hLineEndOffset); if (hLineEndPos.column < hPos.column) { // in virtual space LogicalPosition iPos = myDocumentWindow.hostToInjectedInVirtualSpace(hPos); if (iPos != null) { return iPos; } } int hOffset = myDelegate.logicalPositionToOffset(hPos); int iOffset = myDocumentWindow.hostToInjected(hOffset); return offsetToLogicalPosition(iOffset); }