diff --git a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java
index c259054e8ab8..821694de0170 100644
--- a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java
+++ b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java
@@ -85,7 +85,7 @@ public class XmlSlashTypedHandler extends TypedHandlerDelegate implements XmlTok
final String prevLeafText = prevLeaf.getText();
if ("".equals(prevLeafText) && prevLeaf.getElementType() == XML_END_TAG_START) {
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
- if (tag != null && StringUtil.isNotEmpty(tag.getName())) {
+ if (tag != null && StringUtil.isNotEmpty(tag.getName()) && TreeUtil.findSibling(prevLeaf, XmlTokenType.XML_NAME) == null) {
EditorModificationUtil.insertStringAtCaret(editor, tag.getName() + ">");
return Result.STOP;
}
diff --git a/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java b/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java
index 6a5edda198d8..bcc1afbe797d 100644
--- a/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java
+++ b/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java
@@ -29,4 +29,10 @@ public class XmlTypedHandlersTest extends LightPlatformCodeInsightFixtureTestCas
myFixture.type('/');
myFixture.checkResult("");
}
+
+ public void testGreedyClosing() {
+ myFixture.configureByText(XmlFileType.INSTANCE, "<foo>");
+ myFixture.type('/');
+ myFixture.checkResult("");
+ }
}