@Override
    protected boolean actionPerformedImpl(PsiFile file, Editor editor, XmlAttribute context, int offset) {
        if (!(file instanceof XPathFile)) return false;

        // pattern attribute may not reference variables
        if (XsltSupport.isPatternAttribute(context)) return false;

        final SelectionModel selectionModel = editor.getSelectionModel();
        final boolean hasSelection = selectionModel.hasSelection();
        final int start = selectionModel.getSelectionStart();
        final int end = selectionModel.getSelectionEnd();

        if (hasSelection) {
            final PsiElement xpathElement = file.findElementAt(start);
            if (xpathElement != null) {
                XPathExpression expression = PsiTreeUtil.getParentOfType(xpathElement, XPathExpression.class);
                while (expression != null) {
                    if (expression.getTextRange().getStartOffset() == start) {
                        final int diff = expression.getTextRange().getEndOffset() - end;
                        if (diff == 0) {
                            extractFromExpression(editor, expression);
                            return true;
                        } else if (diff > 0) {
                            break;
                        }
                    }
                    expression = PsiTreeUtil.getParentOfType(expression, XPathExpression.class);
                }
            }
        } else {
            final XPathExpression expression = PsiTreeUtil.getChildOfType(file, XPathExpression.class);
            if (expression != null) {
                final PsiFile containingFile = expression.getContainingFile();
                assert containingFile != null;
                final TextRange range = expression.getTextRange();
                editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
                extractFromExpression(editor, expression);
                return true;
            }
        }

        return false;
    }
@Override
    protected boolean actionPerformedImpl(PsiFile file, Editor editor, XmlAttribute context, int offset)