int physicalToDisplay(int physicalIndex) {
    final XmlAttributeDelegate.VolatileState state = getFreshState();
    if (state == null) return -1;
    if (physicalIndex < 0 || physicalIndex > state.myValueTextRange.getLength()) return -1;
    if (state.myGapPhysicalStarts.length == 0) return physicalIndex;

    final int bsResult = Arrays.binarySearch(state.myGapPhysicalStarts, physicalIndex);

    final int gapIndex;
    if (bsResult > 0) {
      gapIndex = bsResult;
    }
    else if (bsResult < -1) {
      gapIndex = -bsResult - 2;
    }
    else {
      gapIndex = -1;
    }

    if (gapIndex < 0) return physicalIndex;
    final int shift = state.myGapPhysicalStarts[gapIndex] - state.myGapDisplayStarts[gapIndex];
    return Math.max(state.myGapDisplayStarts[gapIndex], physicalIndex - shift);
  }
int physicalToDisplay(int physicalIndex)