From dac1f282f41a396dff2d53d7b44f58ec56ab29a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Tue, 15 Sep 2015 07:45:39 +0200 Subject: [Ide] Fixed bug in search result widget result text. String manipulation inside the markup is much faster than using the gtk attributes. So it's worth the effort of doing that & writing tests. --- .../SearchResultWidget.cs | 25 ++++++++++++++-------- .../ColorizationTests.cs | 16 ++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) (limited to 'main') 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("")) { - if (!closed) + if (opened && !closed) { markupBuilder.Append (""); + 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 (""); + if (opened) { + markupBuilder.Append (""); + 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 (""); } + if (ch == '&') { + inEntity = true; + markupBuilder.Append (ch); + continue; + } markupBuilder.Append (ch); i++; } - if (!closed) + if (!closed && !opened) markupBuilder.Append (""); 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 ("ec.Report.Error (29, loc, \"Cannot implicitly convert type `{0}' to `{1}'\",", result); } + + + + [Test] + public void TestSpanClosingIssue () + { + var result = PangoHelper.ColorMarkupBackground ( + "<Begin>/*</Begin>", + 0, + 17, + new HslColor (1d, 1d, 1d) + ); + Assert.AreEqual ("<Begin>/*</Begin>", result); + } + + } } \ No newline at end of file -- cgit v1.2.3