From f278aaa372579683ce9872355aff4a33eee995f0 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Tue, 29 Dec 2015 15:11:37 +0300 Subject: [PATCH] add '=' if attribute value is missing --- .../src/com/intellij/codeInsight/XmlTagTest.java | 14 ++++++++++++++ .../psi/impl/source/xml/XmlAttributeImpl.java | 1 + 2 files changed, 15 insertions(+) diff --git a/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java b/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java index 6736abbe4fe6..66be6b8a618a 100644 --- a/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java +++ b/xml/tests/src/com/intellij/codeInsight/XmlTagTest.java @@ -1017,4 +1017,18 @@ public class XmlTagTest extends LightCodeInsightTestCase { } }); } + + public void testSetAttributeValue() { + XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("dummy.xml", XmlFileType.INSTANCE, "1", 0, true); + final XmlTag tag = file.getDocument().getRootTag(); + final Document document = file.getViewProvider().getDocument(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + tag.setAttribute("attr", ""); + assertEquals("1", tag.getText()); + assertEquals("1", document.getText()); + } + }); + } } diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java index 14beaf05ad89..a6343628cc3d 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java @@ -104,6 +104,7 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute, Hi } else { if (newValue != null) { + att.addChild(newValue.getTreePrev().copyElement()); att.addChild(newValue.copyElement()); } }