Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@xamarin.com>2012-04-30 20:47:24 +0400
committerMike Krüger <mkrueger@xamarin.com>2012-04-30 20:47:48 +0400
commit71b528f5664cd84fccb022721189548539c736e3 (patch)
tree8888ca56010f1fba0dfc5899c3347dc8ef0f2203
parent6c02268229b5fcc0e23c0d7cbf0f11f62c6f92f9 (diff)
[Core] Improved completion match rank calculation.
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/BacktrackingStringMatcher.cs14
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs8
2 files changed, 17 insertions, 5 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/BacktrackingStringMatcher.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/BacktrackingStringMatcher.cs
index 6d0bad3fdc..b929945fac 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/BacktrackingStringMatcher.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Text/BacktrackingStringMatcher.cs
@@ -72,23 +72,27 @@ namespace MonoDevelop.Core.Text
int nonCapitalMatches = 0;
int matching = 0;
int fragments = 0;
- int lastIndex = 0;
+ int lastIndex = -1;
for (int n = 0; n < lane.Length; n++) {
var ch = filterText [n];
var i = lane [n];
- if (i > lastIndex + 1)
+ Console.WriteLine ("i:" + i);
+ bool newFragment = i > lastIndex + 1;
+ if (newFragment)
fragments++;
lastIndex = i;
- if (ch == name [i]) {
- matching += 1000;
+ if (ch == name [i] || newFragment || i == 0) {
+ matching += 1000 / (1 + fragments);
if (char.IsUpper (ch))
capitalMatches += Math.Max (1, 10000 - 1000 * fragments);
} else {
- var x = 100 * (i + 1) / name.Length;
+ Console.WriteLine (">" + fragments);
+ var x = 100 * (i + 1) / (1 + fragments);
nonCapitalMatches += x;
}
}
matchRank = capitalMatches + matching - fragments + nonCapitalMatches;
+ Console.WriteLine (name + ": " + capitalMatches + "/" + nonCapitalMatches + "/"+ matching + ":" + matchRank);
return true;
}
matchRank = int.MinValue;
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs
index efd2f44ba1..2ac6b0aeb9 100644
--- a/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Gui/CompletionListWindowTests.cs
@@ -722,6 +722,14 @@ namespace MonoDevelop.Ide.Gui
Assert.AreEqual ("A", output);
}
+
+ [Test]
+ public void TestFavorFirstSubword ()
+ {
+ string output = RunSimulation ("", "button\t", true, true, false, "AnotherTestButton", "Button");
+ Assert.AreEqual ("Button", output);
+ }
+
[TestFixtureSetUp]
public void SetUp()
{