Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ViewModels/CommitDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,7 @@ private void CalcRevisionFileSearchSuggestion()
var suggestion = new List<string>();
foreach (var file in _revisionFiles)
{
if (file.Contains(_revisionFileSearchFilter, StringComparison.OrdinalIgnoreCase) &&
file.Length != _revisionFileSearchFilter.Length)
if (file.Contains(_revisionFileSearchFilter, StringComparison.OrdinalIgnoreCase))
suggestion.Add(file);

if (suggestion.Count >= 100)
Expand Down
3 changes: 2 additions & 1 deletion src/Views/RevisionFileTreeView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.RevisionFileTreeView"
x:Name="ThisControl">
<v:RevisionFileRowsListBox ItemsSource="{Binding #ThisControl.Rows}"
<v:RevisionFileRowsListBox x:Name="RowsList"
ItemsSource="{Binding #ThisControl.Rows}"
Background="Transparent"
SelectionMode="Single"
SelectionChanged="OnRowsSelectionChanged"
Expand Down
23 changes: 21 additions & 2 deletions src/Views/RevisionFileTreeView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ public RevisionFileTreeView()

public async Task SetSearchResultAsync(string file)
{
Rows.Clear();
_searchResult.Clear();

var rows = new List<ViewModels.RevisionFileTreeNode>();
Expand Down Expand Up @@ -324,7 +323,27 @@ public async Task SetSearchResultAsync(string file)
MakeRows(rows, _searchResult, 0);
}

Rows.AddRange(rows);
_disableSelectionChangingEvent = true;
try
{
Rows.Clear();
Rows.AddRange(rows);
}
finally
{
_disableSelectionChangingEvent = false;
}

if (!string.IsNullOrEmpty(file))
{
var target = rows.Find(x => !x.IsFolder);
if (target != null)
{
RowsList.SelectedItem = target;
RowsList.ScrollIntoView(target);
}
}

GC.Collect();
}

Expand Down
1 change: 1 addition & 0 deletions src/Views/RevisionFiles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
ItemsSource="{Binding RevisionFileSearchSuggestion}"
MaxHeight="400"
Focusable="True"
SelectionChanged="OnSearchSuggestionSelectionChanged"
KeyDown="OnSearchSuggestionBoxKeyDown">
<ListBox.Styles>
<Style Selector="ListBoxItem">
Expand Down
18 changes: 12 additions & 6 deletions src/Views/RevisionFiles.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ private async void OnSearchBoxTextChanged(object _, TextChangedEventArgs e)
await FileTree.SetSearchResultAsync(null);
}

private async void OnSearchSuggestionSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ListBox { SelectedItem: string content } && !string.IsNullOrEmpty(content))
await FileTree.SetSearchResultAsync(content);
}

private async void OnSearchSuggestionBoxKeyDown(object _, KeyEventArgs e)
{
if (DataContext is not ViewModels.CommitDetail vm)
Expand All @@ -62,9 +68,9 @@ private async void OnSearchSuggestionBoxKeyDown(object _, KeyEventArgs e)
}
else if (e.Key == Key.Enter && SearchSuggestionBox.SelectedItem is string content)
{
vm.RevisionFileSearchFilter = content;
TxtSearchRevisionFiles.CaretIndex = content.Length;
await FileTree.SetSearchResultAsync(vm.RevisionFileSearchFilter);
await FileTree.SetSearchResultAsync(content);
vm.CancelRevisionFileSuggestions();
TxtSearchRevisionFiles.Focus();
e.Handled = true;
}
}
Expand All @@ -77,9 +83,9 @@ private async void OnSearchSuggestionTapped(object sender, TappedEventArgs e)
var content = (sender as StackPanel)?.DataContext as string;
if (!string.IsNullOrEmpty(content))
{
vm.RevisionFileSearchFilter = content;
TxtSearchRevisionFiles.CaretIndex = content.Length;
await FileTree.SetSearchResultAsync(vm.RevisionFileSearchFilter);
await FileTree.SetSearchResultAsync(content);
vm.CancelRevisionFileSuggestions();
TxtSearchRevisionFiles.Focus();
}

e.Handled = true;
Expand Down