diff --git a/CodeMaid.UnitTests/Formatting/XmlFormattingTests.cs b/CodeMaid.UnitTests/Formatting/XmlFormattingTests.cs
index 440b49d5..1876d812 100644
--- a/CodeMaid.UnitTests/Formatting/XmlFormattingTests.cs
+++ b/CodeMaid.UnitTests/Formatting/XmlFormattingTests.cs
@@ -43,6 +43,53 @@ public void XmlFormattingTests_AddSpaceToTagContent()
CommentFormatHelper.AssertEqualAfterFormat(input, expected);
}
+ [TestMethod]
+ [TestCategory("Formatting UnitTests")]
+ public void XmlFormattingTests_AddSpaceToTagContentWithSelfClosingTag()
+ {
+ var input = "";
+ var expected = " ";
+
+ Settings.Default.Formatting_CommentXmlSplitSummaryTagToMultipleLines = false;
+ Settings.Default.Formatting_CommentXmlSpaceTags = true;
+
+ CommentFormatHelper.AssertEqualAfterFormat(input, expected);
+ }
+
+ [TestMethod]
+ [TestCategory("Formatting UnitTests")]
+ public void XmlFormattingTests_AddSpaceToTagContentWithSelfClosingTagMultiline()
+ {
+ var input = "";
+ var expected =
+ "" + Environment.NewLine +
+ "" + Environment.NewLine +
+ "";
+
+ Settings.Default.Formatting_CommentXmlSplitSummaryTagToMultipleLines = true;
+ Settings.Default.Formatting_CommentXmlSpaceTags = true;
+
+ CommentFormatHelper.AssertEqualAfterFormat(input, expected);
+ }
+
+ [TestMethod]
+ [TestCategory("Formatting UnitTests")]
+ public void XmlFormattingTests_AddSpaceToTagContentShouldLeaveNoTrailingWhitespace()
+ {
+ var input = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
+ var expected =
+ "" + Environment.NewLine +
+ "Lorem ipsum dolor sit amet," + Environment.NewLine +
+ "consectetur adipiscing elit." + Environment.NewLine +
+ "";
+
+ Settings.Default.Formatting_CommentWrapColumn = 30;
+ Settings.Default.Formatting_CommentXmlSplitSummaryTagToMultipleLines = true;
+ Settings.Default.Formatting_CommentXmlSpaceTags = true;
+
+ CommentFormatHelper.AssertEqualAfterFormat(input, expected);
+ }
+
[TestMethod]
[TestCategory("Formatting UnitTests")]
public void XmlFormattingTests_AllRootLevelTagsOnNewLine()
diff --git a/CodeMaid/Model/Comments/CommentFormatter.cs b/CodeMaid/Model/Comments/CommentFormatter.cs
index 132b68a6..512da1fb 100644
--- a/CodeMaid/Model/Comments/CommentFormatter.cs
+++ b/CodeMaid/Model/Comments/CommentFormatter.cs
@@ -216,10 +216,6 @@ private bool Parse(ICommentLine line, int indentLevel = 0, int xmlTagLength = 0)
{
NewLine();
}
- else if (!_isFirstWord && Settings.Default.Formatting_CommentXmlSpaceTags)
- {
- Append(CodeCommentHelper.Spacer);
- }
// Always consider the word after the opening tag as the first word to prevent an
// extra space before.
@@ -305,11 +301,6 @@ private bool Parse(ICommentLine line, int indentLevel = 0, int xmlTagLength = 0)
}
}
- if (!forceBreak && Settings.Default.Formatting_CommentXmlSpaceTags)
- {
- Append(CodeCommentHelper.Spacer);
- }
-
if (_currentPosition == 0 || _currentPosition > _commentPrefixLength && forceBreak)
{
// This comment fitted on a single line.
@@ -366,6 +357,11 @@ private bool ParseXml(CommentLineXml line, int indentLevel = 0)
// If true the tag should be alone on it's own line.
tagOnOwnLine |= isLiteralContent;
+ if (!tagOnOwnLine && Settings.Default.Formatting_CommentXmlSpaceTags)
+ {
+ Append(CodeCommentHelper.Spacer);
+ }
+
// If the literal content of an XML tag is set, output that content without formatting.
if (isLiteralContent)
{
@@ -412,9 +408,13 @@ private bool ParseXml(CommentLineXml line, int indentLevel = 0)
if (tagOnOwnLine && !_isFirstWord)
{
NewLine();
+ Indent(indentLevel);
+ }
+ else if (Settings.Default.Formatting_CommentXmlSpaceTags)
+ {
+ Append(CodeCommentHelper.Spacer);
}
- Indent(indentLevel);
Append(line.CloseTag);
return tagOnOwnLine || CommentLineXml.SingleLineElementNames.Contains(line.TagName, StringComparer.OrdinalIgnoreCase);