From 65430c26d0ba672a7e7bbe3b650f72ff851e15d7 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 22 Oct 2015 15:36:15 +0300 Subject: [PATCH] RUBY-17264 Generate xml tag spoils html tag and throws exception --- .../xml/actions/GenerateXmlTagAction.java | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java b/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java index 7f9a8aa7d29d..d091bbb3bdd1 100644 --- a/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java +++ b/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java @@ -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