Skip to content

Commit

Permalink
- Default-select the closest match when typing in a filter string.
Browse files Browse the repository at this point in the history
  • Loading branch information
parnic committed Jul 28, 2015
1 parent efc2d09 commit 77a0b3a
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions ListFiles.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,52 @@ private void FilterProjectItems(object sender, FilterEventArgs e)
}
}

private string GetSelectedFilename()
{
var selectedFile = (lstFiles.SelectedItem as ProjectItemWrapper);
var selectedFilename = string.Empty;
if (selectedFile != null)
{
selectedFilename = selectedFile.Filename;
if (!bSearchFullPath)
{
selectedFilename = Path.GetFileName(selectedFilename);
}
}

return selectedFilename;
}

private void txtFilterChanged(object sender, TextChangedEventArgs e)
{
filterStrings = (sender as TextBox).Text.Split(' ');
viewSource.View.Refresh();
if (lstFiles.SelectedIndex == -1 && lstFiles.Items.Count > 0)
if (lstFiles.Items.Count > 0)
{
lstFiles.SelectedIndex = 0;
if (filterStrings.Length > 0)
{
var selectedFilename = GetSelectedFilename();

foreach (var fileItem in lstFiles.Items)
{
var file = (fileItem as ProjectItemWrapper).Filename;
if (!bSearchFullPath)
{
file = Path.GetFileName(file.ToString());
}

if (string.IsNullOrEmpty(selectedFilename) || file.Length < selectedFilename.Length)
{
lstFiles.SelectedItem = fileItem;
selectedFilename = file;
}
}
}

if (lstFiles.SelectedIndex == -1)
{
lstFiles.SelectedIndex = 0;
}
}
}

Expand Down

0 comments on commit 77a0b3a

Please sign in to comment.