private static int getOffset(@NotNull List<? extends InlineChunk> words, @NotNull CharSequence text, int index) {
    if (index == -1) return 0;
    if (index == words.size()) return text.length();
    InlineChunk chunk = words.get(index);
    assert chunk instanceof NewlineChunk;
    return chunk.getOffset2();
  }
private static int getOffset(@NotNull List<? extends InlineChunk> words, @NotNull CharSequence text, int index)