summaryrefslogtreecommitdiff
path: root/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java')
-rw-r--r--xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java57
1 files changed, 13 insertions, 44 deletions
diff --git a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java
index c50403033c04..2c0143ebeda6 100644
--- a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java
+++ b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java
@@ -36,7 +36,6 @@ import com.intellij.psi.impl.source.xml.XmlTokenImpl;
import com.intellij.psi.templateLanguages.OuterLanguageElement;
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.*;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
@@ -51,6 +50,7 @@ import java.util.Collection;
public class XmlGtTypedHandler extends TypedHandlerDelegate {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.editorActions.TypedHandler");
+ @Override
public Result beforeCharTyped(final char c, final Project project, Editor editor, PsiFile editedFile, final FileType fileType) {
final WebEditorOptions webEditorOptions = WebEditorOptions.getInstance();
if (c == '>' && webEditorOptions != null && webEditorOptions.isAutomaticallyInsertClosingTag() && fileContainsXmlLanguage(editedFile)) {
@@ -182,55 +182,24 @@ public class XmlGtTypedHandler extends TypedHandlerDelegate {
if (BraceMatchingUtil.matchBrace(editor.getDocument().getCharsSequence(), editedFile.getFileType(), iterator, true,true)) {
PsiElement parent = tag.getParent();
boolean hasBalance = true;
-
- while(parent instanceof XmlTag && name.equals(((XmlTag)parent).getName())) {
- ASTNode astNode = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(parent.getNode());
- if (astNode == null) {
+ loop: while(parent instanceof XmlTag) {
+ if (name.equals(((XmlTag)parent).getName())) {
hasBalance = false;
- break;
- }
-
- parent = parent.getParent();
- }
-
- if (hasBalance) {
- hasBalance = false;
- for(ASTNode node=parent.getNode().getLastChildNode(); node != null; node = node.getTreePrev()) {
- ASTNode leaf = node;
- if (leaf.getElementType() == TokenType.ERROR_ELEMENT) {
- ASTNode firstChild = leaf.getFirstChildNode();
- if (firstChild != null) leaf = firstChild;
- else {
- PsiElement psiElement = PsiTreeUtil.nextLeaf(leaf.getPsi());
- leaf = psiElement != null ? psiElement.getNode() : null;
- }
- if (leaf != null && leaf.getElementType() == TokenType.WHITE_SPACE) {
- PsiElement psiElement = PsiTreeUtil.nextLeaf(leaf.getPsi());
- if (psiElement != null) leaf = psiElement.getNode();
- }
+ ASTNode astNode = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(parent.getNode());
+ if (astNode == null) {
+ hasBalance = true;
+ break;
}
-
- if (leaf != null && leaf.getElementType() == XmlTokenType.XML_END_TAG_START) {
- ASTNode treeNext = leaf.getTreeNext();
- IElementType treeNextType;
- if (treeNext != null &&
- ((treeNextType = treeNext.getElementType()) == XmlTokenType.XML_NAME ||
- treeNextType == XmlTokenType.XML_TAG_NAME
- )
- ) {
- if (name.equals(treeNext.getText())) {
- ASTNode parentEndName = parent instanceof XmlTag ?
- XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(parent.getNode()):null;
- hasBalance = !(parent instanceof XmlTag) ||
- parentEndName != null && !parentEndName.getText().equals(name);
- break;
- }
+ for (PsiElement el = parent.getNextSibling(); el != null; el = el.getNextSibling()) {
+ if (el instanceof PsiErrorElement && el.getText().startsWith("</" + name)) {
+ hasBalance = true;
+ break loop;
}
}
}
+ parent = parent.getParent();
}
-
- if (hasBalance) return Result.CONTINUE;
+ if (hasBalance) return Result.CONTINUE;
}
Collection<TextRange> cdataReformatRanges = null;