11using System ;
2- using System . Collections ;
32using System . Collections . Generic ;
43using System . IO ;
54using System . Threading . Tasks ;
@@ -62,12 +61,8 @@ public List<Models.Commit> Commits
6261 get => _commits ;
6362 set
6463 {
65- var lastSelected = SelectedCommit ;
6664 if ( SetProperty ( ref _commits , value ) )
67- {
68- if ( value . Count > 0 && lastSelected != null )
69- SelectedCommit = value . Find ( x => x . SHA . Equals ( lastSelected . SHA , StringComparison . Ordinal ) ) ;
70- }
65+ PostCommitsChanged ( ) ;
7166 }
7267 }
7368
@@ -77,16 +72,14 @@ public Models.CommitGraph Graph
7772 set => SetProperty ( ref _graph , value ) ;
7873 }
7974
80- public Models . Commit SelectedCommit
81- {
82- get => _selectedCommit ;
83- set => SetProperty ( ref _selectedCommit , value ) ;
84- }
85-
86- public long NavigationId
75+ public List < Models . Commit > SelectedCommits
8776 {
88- get => _navigationId ;
89- private set => SetProperty ( ref _navigationId , value ) ;
77+ get => _selectedCommits ;
78+ set
79+ {
80+ if ( SetProperty ( ref _selectedCommits , value ) )
81+ PostSelectedCommitsChanged ( ) ;
82+ }
9083 }
9184
9285 public object DetailContext
@@ -167,8 +160,7 @@ public void NavigateTo(string commitSHA)
167160 var commit = _commits . Find ( x => x . SHA . StartsWith ( commitSHA , StringComparison . Ordinal ) ) ;
168161 if ( commit != null )
169162 {
170- SelectedCommit = commit ;
171- NavigationId = _navigationId + 1 ;
163+ SelectedCommits = [ commit ] ;
172164 return ;
173165 }
174166
@@ -181,7 +173,7 @@ public void NavigateTo(string commitSHA)
181173 Dispatcher . UIThread . Post ( ( ) =>
182174 {
183175 _ignoreSelectionChange = true ;
184- SelectedCommit = null ;
176+ SelectedCommits = [ ] ;
185177
186178 if ( _detailContext is CommitDetail detail )
187179 {
@@ -199,49 +191,30 @@ public void NavigateTo(string commitSHA)
199191 } ) ;
200192 }
201193
202- public void Select ( IList commits )
194+ public void SetSelectedCommitsDirectly ( List < Models . Commit > commits )
203195 {
204- if ( _ignoreSelectionChange )
205- return ;
206-
207- if ( commits . Count == 0 )
196+ if ( _selectedCommits . Count != commits . Count )
208197 {
209- _repo . SearchCommitContext . Selected = null ;
210- DetailContext = null ;
198+ SelectedCommits = commits ;
199+ return ;
211200 }
212- else if ( commits . Count == 1 )
213- {
214- var commit = ( commits [ 0 ] as Models . Commit ) ! ;
215- if ( _repo . SearchCommitContext . Selected == null || ! _repo . SearchCommitContext . Selected . SHA . Equals ( commit . SHA , StringComparison . Ordinal ) )
216- _repo . SearchCommitContext . Selected = _repo . SearchCommitContext . Results ? . Find ( x => x . SHA . Equals ( commit . SHA , StringComparison . Ordinal ) ) ;
217201
218- SelectedCommit = commit ;
219- NavigationId = _navigationId + 1 ;
202+ var hashes = new HashSet < string > ( ) ;
203+ foreach ( var c in _selectedCommits )
204+ hashes . Add ( c . SHA ) ;
220205
221- if ( _detailContext is CommitDetail detail )
222- {
223- detail . Commit = commit ;
224- }
225- else
206+ var equals = true ;
207+ foreach ( var c in commits )
208+ {
209+ if ( ! hashes . Contains ( c . SHA ) )
226210 {
227- var commitDetail = new CommitDetail ( _repo , _commitDetailSharedData ) ;
228- commitDetail . Commit = commit ;
229- DetailContext = commitDetail ;
211+ equals = false ;
212+ break ;
230213 }
231214 }
232- else if ( commits . Count == 2 )
233- {
234- _repo . SearchCommitContext . Selected = null ;
235215
236- var end = commits [ 0 ] as Models . Commit ;
237- var start = commits [ 1 ] as Models . Commit ;
238- DetailContext = new RevisionCompare ( _repo , start , end ) ;
239- }
240- else
241- {
242- _repo . SearchCommitContext . Selected = null ;
243- DetailContext = new Models . Count ( commits . Count ) ;
244- }
216+ if ( ! equals )
217+ SelectedCommits = commits ;
245218 }
246219
247220 public async Task < Models . Commit > GetCommitAsync ( string sha )
@@ -436,14 +409,79 @@ public void CompareWithWorktree(Models.Commit commit)
436409 DetailContext = new RevisionCompare ( _repo , commit , null ) ;
437410 }
438411
412+ private void PostCommitsChanged ( )
413+ {
414+ if ( _commits . Count == 0 ||
415+ _selectedCommits . Count == 0 ||
416+ _selectedCommits . Count > 2 )
417+ {
418+ SelectedCommits = [ ] ;
419+ return ;
420+ }
421+
422+ var set = new HashSet < string > ( ) ;
423+ foreach ( var c in _selectedCommits )
424+ set . Add ( c . SHA ) ;
425+
426+ var selected = new List < Models . Commit > ( ) ;
427+ foreach ( var c in _commits )
428+ {
429+ if ( set . Contains ( c . SHA ) )
430+ {
431+ selected . Add ( c ) ;
432+ set . Remove ( c . SHA ) ;
433+ if ( set . Count == 0 )
434+ break ;
435+ }
436+ }
437+
438+ SelectedCommits = selected ;
439+ }
440+
441+ private void PostSelectedCommitsChanged ( )
442+ {
443+ if ( _ignoreSelectionChange )
444+ return ;
445+
446+ if ( _selectedCommits . Count == 0 )
447+ {
448+ _repo . SearchCommitContext . Selected = null ;
449+ DetailContext = null ;
450+ }
451+ else if ( _selectedCommits . Count == 1 )
452+ {
453+ var c = _selectedCommits [ 0 ] ;
454+ if ( _repo . SearchCommitContext . Selected == null || ! _repo . SearchCommitContext . Selected . SHA . Equals ( c . SHA , StringComparison . Ordinal ) )
455+ _repo . SearchCommitContext . Selected = _repo . SearchCommitContext . Results ? . Find ( x => x . SHA . Equals ( c . SHA , StringComparison . Ordinal ) ) ;
456+
457+ if ( _detailContext is CommitDetail detail )
458+ detail . Commit = c ;
459+ else
460+ DetailContext = new CommitDetail ( _repo , _commitDetailSharedData ) { Commit = c } ;
461+ }
462+ else if ( _selectedCommits . Count == 2 )
463+ {
464+ _repo . SearchCommitContext . Selected = null ;
465+
466+ if ( _detailContext is RevisionCompare compare )
467+ compare . SetTargets ( _selectedCommits [ 0 ] , _selectedCommits [ 1 ] ) ;
468+ else
469+ DetailContext = new RevisionCompare ( _repo , _selectedCommits [ 0 ] , _selectedCommits [ 1 ] ) ;
470+ }
471+ else
472+ {
473+ _repo . SearchCommitContext . Selected = null ;
474+ DetailContext = new Models . Count ( _selectedCommits . Count ) ;
475+ }
476+ }
477+
439478 private Repository _repo = null ;
440479 private CommitDetailSharedData _commitDetailSharedData = null ;
441480 private bool _isLoading = true ;
442481 private List < Models . Commit > _commits = new List < Models . Commit > ( ) ;
443482 private Models . CommitGraph _graph = null ;
444- private Models . Commit _selectedCommit = null ;
483+ private List < Models . Commit > _selectedCommits = [ ] ;
445484 private Models . Bisect _bisect = null ;
446- private long _navigationId = 0 ;
447485 private object _detailContext = null ;
448486 private bool _ignoreSelectionChange = false ;
449487
0 commit comments