Skip to content

Commit f48974b

Browse files
committed
Trying out suggested change from VS Marketplace
This adds another layer of filtering such that if an item isn't matched by looking for each space-delimited word in the search box, we then try to see if each letter in the search term appears, in order, in the uppercase letters from item. So, for example, if we had 3 files in our solution: AssemblyInfo.cs Main.cs README Searching for "ai" would now find the first two items since "AssemblyInfo.cs" contains "ai" in that order as uppercase letters and "Main.cs" contains "ai" per the previous rules. I feel like this might be more intuitive if the rules were tweaked to disregard the capital letter rule, but I can see the merit in this method, so we'll try it out and see how it goes.
1 parent 3b2c37e commit f48974b

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

ListFiles.xaml.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,50 @@ protected void Window_SourceInitialized(object sender, System.EventArgs e)
5252

5353
private void FilterProjectItems(object sender, FilterEventArgs e)
5454
{
55+
var searchStr = (e.Item as ProjectItemWrapper).Filename;
56+
if (!bSearchFullPath)
57+
{
58+
searchStr = Path.GetFileName(searchStr);
59+
}
60+
var searchStrLower = searchStr.ToLower();
61+
5562
e.Accepted = true;
5663
if (!string.IsNullOrEmpty(FilterText))
5764
{
5865
foreach (var filter in filterStrings)
5966
{
60-
var searchStr = (e.Item as ProjectItemWrapper).Filename.ToLower();
61-
if (!bSearchFullPath)
67+
if (!string.IsNullOrWhiteSpace(filter) && !searchStrLower.Contains(filter.ToLower()))
68+
{
69+
e.Accepted = false;
70+
break;
71+
}
72+
}
73+
}
74+
75+
if (!e.Accepted)
76+
{
77+
int filterTextIdx = 0;
78+
foreach (var ch in searchStr)
79+
{
80+
if (ch != char.ToUpper(ch))
6281
{
63-
searchStr = Path.GetFileName(searchStr);
82+
continue;
6483
}
6584

66-
if (!string.IsNullOrWhiteSpace(filter) && !searchStr.Contains(filter.ToLower()))
85+
if (ch == char.ToUpper(FilterText[filterTextIdx]))
86+
{
87+
filterTextIdx++;
88+
}
89+
if (filterTextIdx == FilterText.Length)
6790
{
68-
e.Accepted = false;
6991
break;
7092
}
7193
}
94+
95+
if (filterTextIdx == FilterText.Length)
96+
{
97+
e.Accepted = true;
98+
}
7299
}
73100
}
74101

0 commit comments

Comments
 (0)