diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java index f35bebce3715..5c301f56635b 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java @@ -21,9 +21,11 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil; import com.intellij.lang.ASTNode; +import com.intellij.lang.Language; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.MarkupModelEx; @@ -37,6 +39,8 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlChildRole; import com.intellij.psi.xml.XmlTag; import com.intellij.psi.xml.XmlTokenType; @@ -83,15 +87,33 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { return; } - final PsiElement[] elements = - BreadcrumbsXmlWrapper.getLinePsiElements(myEditor.getCaretModel().getOffset(), myFile.getVirtualFile(), myProject, myInfoProvider); + final int offset = myEditor.getCaretModel().getOffset(); + PsiElement[] elements = BreadcrumbsXmlWrapper.getLinePsiElements(offset, + myFile.getVirtualFile(), + myProject, myInfoProvider); if (elements == null || elements.length == 0) { return; } if (!XmlTagTreeHighlightingUtil.containsTagsWithSameName(elements)) { - return; + elements = PsiElement.EMPTY_ARRAY; + final FileViewProvider provider = myFile.getViewProvider(); + for (Language language : provider.getLanguages()) { + PsiElement element = provider.findElementAt(offset, language); + if (!isTagStartOrEnd(element)) { + element = null; + } + if (element == null && offset > 0) { + element = provider.findElementAt(offset - 1, language); + if (!isTagStartOrEnd(element)) element = null; + } + + final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class); + if (tag != null) { + elements = new PsiElement[] {tag}; + } + } } for (int i = elements.length - 1; i >= 0; i--) { @@ -101,6 +123,13 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { } } + private static boolean isTagStartOrEnd(@Nullable PsiElement element) { + if (element == null) return false; + final IElementType type = element.getNode().getElementType(); + if (type == XmlTokenType.XML_NAME) return isTagStartOrEnd(element.getNextSibling()) || isTagStartOrEnd(element.getPrevSibling()); + return type == XmlTokenType.XML_START_TAG_START || type == XmlTokenType.XML_END_TAG_START || type == XmlTokenType.XML_TAG_END; + } + @Nullable private static Pair getTagRanges(XmlTag tag) { final ASTNode tagNode = tag.getNode(); @@ -160,7 +189,8 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { final MarkupModel markupModel = myEditor.getMarkupModel(); final Color[] baseColors = XmlTagTreeHighlightingUtil.getBaseColors(); - final Color[] colorsForEditor = toColorsForEditor(baseColors); + final Color[] colorsForEditor = count > 1 ? toColorsForEditor(baseColors) : + new Color[] {myEditor.getColorsScheme().getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES).getBackgroundColor()}; final Color[] colorsForLineMarkers = toColorsForLineMarkers(baseColors); final List newHighlighters = new ArrayList(); @@ -192,7 +222,7 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { final int end = pair.second != null ? pair.second.getEndOffset() : pair.first.getEndOffset(); final Color lineMarkerColor = colorsForLineMarkers[i]; - if (lineMarkerColor != null && start != end) { + if (count > 1 && lineMarkerColor != null && start != end) { final RangeHighlighter highlighter = createHighlighter(markupModel, new TextRange(start, end), lineMarkerColor); newHighlighters.add(highlighter); }