From 42b38f5c3996a05c4f729a5b6b0a21eb4685f638 Mon Sep 17 00:00:00 2001 From: weiningwei Date: Wed, 26 Aug 2026 20:43:51 +0800 Subject: [PATCH] ux: preview the selected file when navigating file search results --- src/ViewModels/CommitDetail.cs | 3 +-- src/Views/RevisionFileTreeView.axaml | 3 ++- src/Views/RevisionFileTreeView.axaml.cs | 23 +++++++++++++++++++++-- src/Views/RevisionFiles.axaml | 1 + src/Views/RevisionFiles.axaml.cs | 18 ++++++++++++------ 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 66291659a..c49ac5fe7 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -662,8 +662,7 @@ private void CalcRevisionFileSearchSuggestion() var suggestion = new List(); 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) diff --git a/src/Views/RevisionFileTreeView.axaml b/src/Views/RevisionFileTreeView.axaml index 025ba4d79..4d4c9d034 100644 --- a/src/Views/RevisionFileTreeView.axaml +++ b/src/Views/RevisionFileTreeView.axaml @@ -8,7 +8,8 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.RevisionFileTreeView" x:Name="ThisControl"> - (); @@ -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(); } diff --git a/src/Views/RevisionFiles.axaml b/src/Views/RevisionFiles.axaml index 9ff113c57..80ce1f980 100644 --- a/src/Views/RevisionFiles.axaml +++ b/src/Views/RevisionFiles.axaml @@ -63,6 +63,7 @@ ItemsSource="{Binding RevisionFileSearchSuggestion}" MaxHeight="400" Focusable="True" + SelectionChanged="OnSearchSuggestionSelectionChanged" KeyDown="OnSearchSuggestionBoxKeyDown">