mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
insert paired end instead of shorthand if needed
#IDEA-157251 fixed
This commit is contained in:
@@ -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) ? "></" + tagAtCaret.getName() + ">" : "/>" :
|
||||
">");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<tab<caret>
|
||||
@@ -0,0 +1 @@
|
||||
<br<caret>
|
||||
@@ -0,0 +1 @@
|
||||
<br/><caret>
|
||||
@@ -0,0 +1 @@
|
||||
<table><caret></table>
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user