diff options
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs | 25 | ||||
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs | 16 |
2 files changed, 32 insertions, 9 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs index c96e994d29..9e9774a8c3 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs @@ -852,7 +852,7 @@ namespace MonoDevelop.Ide.FindInFiles public static string ColorMarkupBackground (string textMarkup, int startIndex, int endIndex, HslColor searchColor) { var markupBuilder = new StringBuilder(); - bool inMarkup = false, inEntity = false, closed = false; + bool inMarkup = false, inEntity = false, closed = false, opened = false; int i = 0; for (int j = 0; j < textMarkup.Length; j++) { var ch = textMarkup [j]; @@ -869,8 +869,10 @@ namespace MonoDevelop.Ide.FindInFiles inMarkup = false; markupBuilder.Append (ch); if (i > startIndex && markupBuilder.ToString ().EndsWith("</span>")) { - if (!closed) + if (opened && !closed) { markupBuilder.Append ("</span>"); + opened = false; + } markupBuilder.Append (textMarkup.Substring(j + 1)); return ColorMarkupBackground (markupBuilder.ToString (), i, endIndex, searchColor); } @@ -880,28 +882,33 @@ namespace MonoDevelop.Ide.FindInFiles continue; } if (i == endIndex) { - markupBuilder.Append ("</span>"); + if (opened) { + markupBuilder.Append ("</span>"); + opened = false; + } markupBuilder.Append (textMarkup.Substring (j)); closed = true; break; } - if (ch == '&') { - inEntity = true; - markupBuilder.Append (ch); - continue; - } + if (ch == '<') { inMarkup = true; markupBuilder.Append (ch); continue; } if (i == startIndex) { + opened = true; markupBuilder.Append ("<span background=\"" + ColorToPangoMarkup (searchColor) + "\">"); } + if (ch == '&') { + inEntity = true; + markupBuilder.Append (ch); + continue; + } markupBuilder.Append (ch); i++; } - if (!closed) + if (!closed && !opened) markupBuilder.Append ("</span>"); return markupBuilder.ToString (); } diff --git a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs index 60d6e6d1c3..7f39e373c8 100644 --- a/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs +++ b/main/tests/UnitTests/MonoDevelop.Ide.FindInFiles/ColorizationTests.cs @@ -88,5 +88,21 @@ namespace MonoDevelop.Ide.FindInFiles ); Assert.AreEqual ("<span foreground=\"#000000\">ec.Report.Error <span background=\"#FFFFFF\">(</span></span><span foreground=\"#A40000\"><span background=\"#FFFFFF\">29</span></span><span foreground=\"#000000\"><span background=\"#FFFFFF\">,</span> loc, </span><span foreground=\"#A40000\">\"Cannot implicitly convert type `{0}' to `{1}'\"</span><span foreground=\"#000000\">,</span>", result); } + + + + [Test] + public void TestSpanClosingIssue () + { + var result = PangoHelper.ColorMarkupBackground ( + "<span foreground=\"#000000\"><</span><span foreground=\"#204987\">Begin</span><span foreground=\"#000000\">>/*</</span><span foreground=\"#204987\">Begin</span><span foreground=\"#000000\">></span>", + 0, + 17, + new HslColor (1d, 1d, 1d) + ); + Assert.AreEqual ("<span foreground=\"#000000\"><span background=\"#FFFFFF\"><</span></span><span foreground=\"#204987\"><span background=\"#FFFFFF\">Begin</span></span><span foreground=\"#000000\"><span background=\"#FFFFFF\">>/*</</span></span><span foreground=\"#204987\"><span background=\"#FFFFFF\">Begin</span></span><span foreground=\"#000000\"><span background=\"#FFFFFF\">></span></span>", result); + } + + } }
\ No newline at end of file |