private static int getLastTopLevelIndexBefore(@NotNull CachedData cachedData, int offset) {
    int[] endOffsets = cachedData.topEndOffsets;

    if (endOffsets == null) return -1;

    offset--; // end offsets are decremented in cache
    int i = Arrays.binarySearch(endOffsets, offset);
    return i < 0 ? - i - 2 : i;
  }
private static int getLastTopLevelIndexBefore(@NotNull CachedData cachedData, int offset)