List<TextRange> (@NotNull PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) { ArrayList<TextRange> result = new ArrayList<>(); addWordRange(editorText, cursorOffset, result); TextRange range = expandSelection(e, editorText, cursorOffset, cursorOffset); if (range != null) { result.add(range); while (true) { TextRange next = expandSelection(e, editorText, range.getStartOffset(), range.getEndOffset()); if (next == null || range.contains(next)) { break; } result.add(next); range = next; } } return result; }