@Override
  public PsiElement @NotNull [] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
    // adjust start/end
    PsiElement element1 = file.findElementAt(startOffset);
    PsiElement element2 = file.findElementAt(endOffset - 1);
    if (element1 instanceof PsiWhiteSpace) {
      startOffset = element1.getTextRange().getEndOffset();
    }
    if (element2 instanceof PsiWhiteSpace) {
      endOffset = element2.getTextRange().getStartOffset();
    }

    RegExpElement pattern = findElementAtStrict(file, startOffset, endOffset, RegExpPattern.class);
    if (pattern != null) return new RegExpElement[]{pattern};

    RegExpElement branch = findElementAtStrict(file, startOffset, endOffset, RegExpBranch.class);
    if (branch != null) return new RegExpElement[]{branch};

    List<PsiElement> atoms = new ArrayList<>();
    RegExpAtom atom = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, RegExpAtom.class);
    for (; atom != null; atom = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, RegExpAtom.class)) {
      atoms.add(atom);
      startOffset = atom.getTextRange().getEndOffset();

      // handle embedded whitespace
      if ((element1 = file.findElementAt(startOffset)) instanceof PsiWhiteSpace) {
        startOffset = element1.getTextRange().getEndOffset();
        atoms.add(element1);
      }
    }

    if (startOffset == endOffset && atoms.size() > 0) {
      PsiElement[] elements = PsiUtilCore.toPsiElementArray(atoms);
      if ((atoms.size() == 1 || PsiTreeUtil.findCommonParent(elements) == elements[0].getParent())) {
        return elements;
      }
    }
    return PsiElement.EMPTY_ARRAY;
  }
@Override
  public PsiElement @NotNull [] getElementsToSurround(PsiFile file, int startOffset, int endOffset)