Skip to content

Commit b5d0f9d

Browse files
committed
feat: remember the multi selected commit if avalible
- it is usefull for multi selection. - like two revision compare, - it will keep those selection for compare while filter changed - and it will restore those selection if grapht fresh
1 parent 740712b commit b5d0f9d

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/ViewModels/Histories.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Linq;
56
using System.Threading.Tasks;
67

78
using Avalonia.Controls;
@@ -83,6 +84,12 @@ public Models.Commit SelectedCommit
8384
set => SetProperty(ref _selectedCommit, value);
8485
}
8586

87+
public List<Models.Commit> LastSelectedCommits
88+
{
89+
get => _lastSelectedCommits;
90+
private set => SetProperty(ref _lastSelectedCommits, value);
91+
}
92+
8693
public long NavigationId
8794
{
8895
get => _navigationId;
@@ -252,6 +259,13 @@ public void Select(IList commits)
252259
_repo.SearchCommitContext.Selected = null;
253260
DetailContext = new Models.Count(commits.Count);
254261
}
262+
263+
_repo.SelectedCommits = commits.Cast<Models.Commit>().ToList();
264+
}
265+
266+
public void MarkCommitsAsSelected(IList<Models.Commit> commits)
267+
{
268+
LastSelectedCommits = _commits.Where(x => commits.Any(y => y.SHA == x.SHA)).ToList();
255269
}
256270

257271
public async Task<Models.Commit> GetCommitAsync(string sha)
@@ -466,6 +480,7 @@ public void CompareWithWorktree(Models.Commit commit)
466480
private CommitDetailSharedData _commitDetailSharedData = null;
467481
private bool _isLoading = true;
468482
private List<Models.Commit> _commits = new List<Models.Commit>();
483+
private List<Models.Commit> _lastSelectedCommits = [];
469484
private Models.CommitGraph _graph = null;
470485
private Models.Commit _selectedCommit = null;
471486
private Models.Bisect _bisect = null;

src/ViewModels/Repository.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ public SearchCommitContext SearchCommitContext
282282
get => _searchCommitContext;
283283
}
284284

285+
public List<Models.Commit> SelectedCommits
286+
{
287+
get => _selectCommits;
288+
set => SetProperty(ref _selectCommits, value);
289+
}
290+
285291
public bool IsLocalBranchGroupExpanded
286292
{
287293
get => _uiStates.IsLocalBranchesExpandedInSideBar;
@@ -1219,6 +1225,7 @@ public void RefreshCommits()
12191225
{
12201226
if (_cancellationRefreshCommits is { IsCancellationRequested: false })
12211227
_cancellationRefreshCommits.Cancel();
1228+
var oldSelectedCommits = _selectCommits.ToList();
12221229

12231230
_cancellationRefreshCommits = new CancellationTokenSource();
12241231
var token = _cancellationRefreshCommits.Token;
@@ -1248,6 +1255,8 @@ public void RefreshCommits()
12481255

12491256
BisectState = _histories.UpdateBisectInfo();
12501257

1258+
_histories.MarkCommitsAsSelected(oldSelectedCommits);
1259+
12511260
if (!string.IsNullOrEmpty(_navigateToCommitDelayed))
12521261
NavigateToCommit(_navigateToCommitDelayed);
12531262
}
@@ -1957,6 +1966,7 @@ private async Task AutoFetchOnUIThread()
19571966

19581967
private bool _isSearchingCommits = false;
19591968
private SearchCommitContext _searchCommitContext = null;
1969+
private List<Models.Commit> _selectCommits = new List<Models.Commit>();
19601970

19611971
private string _filter = string.Empty;
19621972
private List<Models.Remote> _remotes = [];

src/Views/Histories.axaml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ public long NavigationId
123123
set => SetValue(NavigationIdProperty, value);
124124
}
125125

126+
public static readonly StyledProperty<List<Models.Commit>> LastSelectedCommitsProperty =
127+
AvaloniaProperty.Register<Histories, List<Models.Commit>>(nameof(LastSelectedCommits));
128+
129+
public List<Models.Commit> LastSelectedCommits
130+
{
131+
get => GetValue(LastSelectedCommitsProperty);
132+
set => SetValue(LastSelectedCommitsProperty, value);
133+
}
134+
126135
public static readonly StyledProperty<bool> IsScrollToTopVisibleProperty =
127136
AvaloniaProperty.Register<Histories, bool>(nameof(IsScrollToTopVisible));
128137

@@ -146,6 +155,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
146155
if (CommitListContainer is { SelectedItems.Count: 1, IsLoaded: true } dataGrid)
147156
dataGrid.ScrollIntoView(dataGrid.SelectedItem, null);
148157
}
158+
if (change.Property == LastSelectedCommitsProperty)
159+
{
160+
if (LastSelectedCommits?.Count > 1 &&
161+
(CommitListContainer is DataGrid { IsLoaded: true } dataGrid))
162+
{
163+
foreach (var c in LastSelectedCommits)
164+
{
165+
dataGrid.SelectedItems.Add(c);
166+
}
167+
}
168+
}
169+
149170
}
150171

151172
private void OnCommitListLoaded(object sender, RoutedEventArgs e)

src/Views/Repository.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424
<Setter Property="CornerRadius" Value="4"/>
425425
</Style>
426426
</ListBox.Styles>
427-
<ListBox.ItemTemplate>
427+
<ListBox.ItemTemplate>
428428
<DataTemplate DataType="vm:Worktree">
429429
<Border Height="24"
430430
Background="Transparent"
@@ -450,7 +450,7 @@
450450
<TextBlock Grid.Row="0" Grid.Column="3"
451451
Margin="6,0,0,0"
452452
Text="{Binding Branch, Mode=OneWay}"/>
453-
453+
454454
<TextBlock Grid.Row="1" Grid.Column="0"
455455
Classes="info_label"
456456
HorizontalAlignment="Left" VerticalAlignment="Center"
@@ -926,6 +926,7 @@
926926
Bisect="{Binding Bisect}"
927927
IssueTrackers="{Binding $parent[v:Repository].((vm:Repository)DataContext).IssueTrackers}"
928928
OnlyHighlightCurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).OnlyHighlightCurrentBranchInHistory}"
929+
LastSelectedCommits="{Binding LastSelectedCommits}"
929930
NavigationId="{Binding NavigationId}"/>
930931
</DataTemplate>
931932

0 commit comments

Comments
 (0)