feature: add auto complete box for searching commits by file path

This commit is contained in:
leo 2024-07-30 15:59:54 +08:00
parent addfb449cc
commit 7f8b8a19a0
No known key found for this signature in database
4 changed files with 235 additions and 35 deletions

View file

@ -29,11 +29,33 @@ namespace SourceGit.Views
private void OnSearchKeyDown(object _, KeyEventArgs e)
{
var repo = DataContext as ViewModels.Repository;
if (e.Key == Key.Enter)
{
if (DataContext is ViewModels.Repository repo && !string.IsNullOrWhiteSpace(repo.SearchCommitFilter))
if (!string.IsNullOrWhiteSpace(repo.SearchCommitFilter))
repo.StartSearchCommits();
e.Handled = true;
}
else if (e.Key == Key.Down)
{
if (repo.IsSearchCommitSuggestionOpen)
{
SearchSuggestionBox.Focus(NavigationMethod.Tab);
SearchSuggestionBox.SelectedIndex = 0;
}
e.Handled = true;
}
else if (e.Key == Key.Escape)
{
if (repo.IsSearchCommitSuggestionOpen)
{
repo.SearchCommitFilterSuggestion.Clear();
repo.IsSearchCommitSuggestionOpen = false;
}
e.Handled = true;
}
}
@ -272,5 +294,37 @@ namespace SourceGit.Views
}
}
}
private void OnSearchSuggestionBoxKeyDown(object sender, KeyEventArgs e)
{
var repo = DataContext as ViewModels.Repository;
if (e.Key == Key.Escape)
{
repo.IsSearchCommitSuggestionOpen = false;
repo.SearchCommitFilterSuggestion.Clear();
e.Handled = true;
}
else if (e.Key == Key.Enter && SearchSuggestionBox.SelectedItem is string content)
{
repo.SearchCommitFilter = content;
TxtSearchCommitsBox.CaretIndex = content.Length;
repo.StartSearchCommits();
e.Handled = true;
}
}
private void OnSearchSuggestionDoubleTapped(object sender, TappedEventArgs e)
{
var repo = DataContext as ViewModels.Repository;
var content = (sender as StackPanel)?.DataContext as string;
if (!string.IsNullOrEmpty(content))
{
repo.SearchCommitFilter = content;
TxtSearchCommitsBox.CaretIndex = content.Length;
repo.StartSearchCommits();
}
e.Handled = true;
}
}
}