diff options
author | Tor Norbye <tnorbye@google.com> | 2010-11-04 17:28:45 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-11-04 17:28:45 -0700 |
commit | 12479c5035e36a687499abb2079bf645dc395aa3 (patch) | |
tree | 8bcfbf93a662d2cb9e7f61c5da4f7ab44f1ff8a0 | |
parent | 35ab4df68dd5fc3f91d718073f02ff8e5042dbf5 (diff) | |
parent | 2a6dd1206b3cec798d3c78a78261986635b31973 (diff) | |
download | sdk-12479c5035e36a687499abb2079bf645dc395aa3.zip sdk-12479c5035e36a687499abb2079bf645dc395aa3.tar.gz sdk-12479c5035e36a687499abb2079bf645dc395aa3.tar.bz2 |
Merge "Fix XML editing whitespace handling"
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java index 55cc90b..1d9cacf 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java @@ -833,11 +833,20 @@ public class UiElementNode implements IPropertySource { xmlNextSibling = uiNextSibling.getXmlNode(); } + // If this is the first element we are adding into a new element, + // we need to insert a newline at the beginning too. Unless it's already + // there, which is the case for the root element created for the .xml template + // files - but this is why we use the xml node list rather than the element + // count. + if (parentXmlNode.getChildNodes().getLength() == 0) { + parentXmlNode.insertBefore(doc.createTextNode("\n"), xmlNextSibling); //$NON-NLS-1$ + } + parentXmlNode.insertBefore(mXmlNode, xmlNextSibling); // Insert a separator after the tag, to make it easier to read - Text sep = doc.createTextNode("\n"); - parentXmlNode.appendChild(sep); + Text sep = doc.createTextNode("\n"); //$NON-NLS-1$ + parentXmlNode.insertBefore(sep, xmlNextSibling); // Set all initial attributes in the XML node if they are not empty. // Iterate on the descriptor list to get the desired order and then use the @@ -881,8 +890,16 @@ public class UiElementNode implements IPropertySource { if (xml_parent == null) { xml_parent = getXmlDocument(); } + Node nextSibling = old_xml_node.getNextSibling(); old_xml_node = xml_parent.removeChild(old_xml_node); + // Remove following text node if it's just blank space, to account for + // the fact what we add these when we insert nodes. + if (nextSibling != null && nextSibling.getNodeType() == Node.TEXT_NODE + && nextSibling.getNodeValue().trim().length() == 0) { + xml_parent.removeChild(nextSibling); + } + invokeUiUpdateListeners(UiUpdateState.DELETED); return old_xml_node; } @@ -1227,6 +1244,7 @@ public class UiElementNode implements IPropertySource { * @since GLE1 * @deprecated Used by GLE1. Should be deprecated for GLE2. */ + @Deprecated public void setEditData(Object data) { mEditData = data; } |