mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-17264 Generate xml tag spoils html tag and throws exception
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user