int (@NotNull CharSequence text, @NotNull List<? extends InlineChunk> words, int offset, int count, boolean leftToRight) { for (int i = 0; i < count; i++) { InlineChunk word1; InlineChunk word2; if (leftToRight) { word1 = words.get(offset + i); word2 = words.get(offset + i + 1); } else { word1 = words.get(offset - i - 1); word2 = words.get(offset - i); } if (isSeparatedWithWhitespace(text, word1, word2)) return i + 1; } return -1; }