diff --git a/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java b/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java index bc6b6fab8112..d13430d54e57 100644 --- a/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java +++ b/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java @@ -28,6 +28,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.*; import com.intellij.util.IncorrectOperationException; import com.intellij.util.text.CharArrayUtil; +import com.intellij.xml.util.CheckEmptyTagInspection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -123,7 +124,7 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor { final CharSequence text2insert = getClosingPart(xmlAttribute, tagAtCaret, true); doc.insertString(insertionOffset, text2insert); - caretTo = insertionOffset + text2insert.length(); + caretTo = insertionOffset + (text2insert.length() > 2 ? 1 : text2insert.length()); } commitChanges(project, editor, psiFile, caretTo, null); @@ -199,7 +200,10 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor { } protected String getClosingPart(final XmlAttribute xmlAttribute, final XmlTag tagAtCaret, final boolean emptyTag) { - return getClosingQuote(xmlAttribute) + (emptyTag ? "/>" : ">"); + return getClosingQuote(xmlAttribute) + + (emptyTag ? + CheckEmptyTagInspection.isTagWithEmptyEndNotAllowed(tagAtCaret) ? ">" : "/>" : + ">"); } @NotNull diff --git a/xml/tests/src/com/intellij/codeInsight/completion/XmlSmartEnterTest.java b/xml/tests/src/com/intellij/codeInsight/completion/XmlSmartEnterTest.java index b001b66795ed..1c4972595f97 100644 --- a/xml/tests/src/com/intellij/codeInsight/completion/XmlSmartEnterTest.java +++ b/xml/tests/src/com/intellij/codeInsight/completion/XmlSmartEnterTest.java @@ -104,6 +104,11 @@ public class XmlSmartEnterTest extends LightCodeInsightTestCase { _doTest("idea103417_2.xml", "idea103417_2_after.xml"); } + public void testEmptyHtml() throws Exception { + _doTestCompletion("EmptyHtml.html", "EmptyHtml_after.html"); + _doTestCompletion("EmptyHtml2.html", "EmptyHtml2_after.html"); + } + private void _doTestCompletion(final String name, final String after_name) throws Exception { configureByFile(BASE_PATH + "/" + name); performCompletionAction(); diff --git a/xml/tests/testData/smartEnter/EmptyHtml.html b/xml/tests/testData/smartEnter/EmptyHtml.html new file mode 100644 index 000000000000..ab0f4d1b7f92 --- /dev/null +++ b/xml/tests/testData/smartEnter/EmptyHtml.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xml/tests/testData/smartEnter/EmptyHtml2.html b/xml/tests/testData/smartEnter/EmptyHtml2.html new file mode 100644 index 000000000000..4a0138f23faa --- /dev/null +++ b/xml/tests/testData/smartEnter/EmptyHtml2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xml/tests/testData/smartEnter/EmptyHtml2_after.html b/xml/tests/testData/smartEnter/EmptyHtml2_after.html new file mode 100644 index 000000000000..09604a12dd37 --- /dev/null +++ b/xml/tests/testData/smartEnter/EmptyHtml2_after.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/xml/tests/testData/smartEnter/EmptyHtml_after.html b/xml/tests/testData/smartEnter/EmptyHtml_after.html new file mode 100644 index 000000000000..9b90758d4cb4 --- /dev/null +++ b/xml/tests/testData/smartEnter/EmptyHtml_after.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/xml/xml-analysis-impl/src/com/intellij/xml/util/CheckEmptyTagInspection.java b/xml/xml-analysis-impl/src/com/intellij/xml/util/CheckEmptyTagInspection.java index 97b951da0a3a..3917ff0ddce0 100644 --- a/xml/xml-analysis-impl/src/com/intellij/xml/util/CheckEmptyTagInspection.java +++ b/xml/xml-analysis-impl/src/com/intellij/xml/util/CheckEmptyTagInspection.java @@ -77,7 +77,7 @@ public class CheckEmptyTagInspection extends XmlSuppressableInspectionTool { }; } - static boolean isTagWithEmptyEndNotAllowed(final XmlTag tag) { + public static boolean isTagWithEmptyEndNotAllowed(final XmlTag tag) { String tagName = tag.getName(); if (tag instanceof HtmlTag) tagName = tagName.toLowerCase();