RUBY-17264 Generate xml tag spoils html tag and throws exception

This commit is contained in:
Dmitry Avdeev
2015-10-22 15:38:39 +03:00
parent fa760614b7
commit 65430c26d0
@@ -303,46 +303,16 @@ public class GenerateXmlTagAction extends SimpleCodeInsightAction {
}
}
private static boolean isInsideTagBody(@NotNull Editor editor, @NotNull PsiFile file) {
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
while (element != null && !(element.getParent() instanceof XmlTag)) {
element = element.getParent();
}
if (element == null) {
return false;
}
if (element.getNode().getElementType() == XmlTokenType.XML_START_TAG_START) {
return true;
} else {
PsiElement left = element.getPrevSibling();
while (left != null && left.getNode().getElementType() != XmlTokenType.XML_TAG_END) {
left = left.getPrevSibling();
}
if (left == null) {
return false;
}
PsiElement right = element.getNextSibling();
while (right != null && right.getNode().getElementType() != XmlTokenType.XML_END_TAG_START) {
right = right.getNextSibling();
}
if (right == null) {
return false;
}
return true;
}
private static boolean isInsideTagBody(XmlTag contextTag, @NotNull Editor editor) {
return contextTag.getValue().getTextRange().contains(editor.getCaretModel().getOffset());
}
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!(file instanceof XmlFile)) return false;
if (!isInsideTagBody(editor, file)) {
return false;
}
XmlTag contextTag = getContextTag(editor, file);
return contextTag != null && contextTag.getDescriptor() != null;
return contextTag != null && isInsideTagBody(contextTag, editor) && contextTag.getDescriptor() != null;
}
@Override