@@ -44,7 +44,7 @@ pub struct CommitList {
4444 highlighted_selection : Option < usize > ,
4545 items : ItemBatch ,
4646 highlights : Option < Rc < IndexSet < CommitId > > > ,
47- commits : Vec < CommitId > ,
47+ commits : IndexSet < CommitId > ,
4848 marked : Vec < ( usize , CommitId ) > ,
4949 scroll_state : ( Instant , f32 ) ,
5050 tags : Option < Tags > ,
@@ -72,7 +72,7 @@ impl CommitList {
7272 marked : Vec :: with_capacity ( 2 ) ,
7373 selection : 0 ,
7474 highlighted_selection : None ,
75- commits : Vec :: new ( ) ,
75+ commits : IndexSet :: new ( ) ,
7676 highlights : None ,
7777 scroll_state : ( Instant :: now ( ) , 0_f32 ) ,
7878 tags : None ,
@@ -100,7 +100,7 @@ impl CommitList {
100100
101101 ///
102102 pub fn copy_items ( & self ) -> Vec < CommitId > {
103- self . commits . clone ( )
103+ self . commits . iter ( ) . copied ( ) . collect_vec ( )
104104 }
105105
106106 ///
@@ -224,7 +224,7 @@ impl CommitList {
224224 }
225225
226226 ///
227- pub fn set_commits ( & mut self , commits : Vec < CommitId > ) {
227+ pub fn set_commits ( & mut self , commits : IndexSet < CommitId > ) {
228228 if commits != self . commits {
229229 self . items . clear ( ) ;
230230 self . commits = commits;
@@ -268,10 +268,10 @@ impl CommitList {
268268
269269 ///
270270 pub fn select_commit ( & mut self , id : CommitId ) -> Result < ( ) > {
271- let position = self . commits . iter ( ) . position ( | & x| x == id) ;
271+ let index = self . commits . get_index_of ( & id) ;
272272
273- if let Some ( position ) = position {
274- self . selection = position ;
273+ if let Some ( index ) = index {
274+ self . selection = index ;
275275 self . set_highlighted_selection_index ( ) ;
276276 Ok ( ( ) )
277277 } else {
@@ -332,35 +332,39 @@ impl CommitList {
332332 & mut self ,
333333 scroll : ScrollType ,
334334 ) -> Result < bool > {
335- let old_selection = self . selection ;
335+ let ( current_index, selection_max) =
336+ self . highlighted_selection_info ( ) ;
336337
337- loop {
338- let new_selection = match scroll {
339- ScrollType :: Up => self . selection . saturating_sub ( 1 ) ,
340- ScrollType :: Down => self . selection . saturating_add ( 1 ) ,
341-
342- //TODO: support this?
343- // ScrollType::Home => 0,
344- // ScrollType::End => self.selection_max(),
345- _ => return Ok ( false ) ,
346- } ;
338+ let new_index = match scroll {
339+ ScrollType :: Up => current_index. saturating_sub ( 1 ) ,
340+ ScrollType :: Down => current_index. saturating_add ( 1 ) ,
347341
348- let new_selection =
349- cmp:: min ( new_selection, self . selection_max ( ) ) ;
350- let selection_changed = new_selection != self . selection ;
342+ //TODO: support this?
343+ // ScrollType::Home => 0,
344+ // ScrollType::End => self.selection_max(),
345+ _ => return Ok ( false ) ,
346+ } ;
351347
352- if !selection_changed {
353- self . selection = old_selection;
354- return Ok ( false ) ;
355- }
348+ let new_index =
349+ cmp:: min ( new_index, selection_max. saturating_sub ( 1 ) ) ;
356350
357- self . selection = new_selection ;
351+ let index_changed = new_index != current_index ;
358352
359- if self . selection_highlighted ( ) {
360- self . set_highlighted_selection_index ( ) ;
361- return Ok ( true ) ;
362- }
353+ if !index_changed {
354+ return Ok ( false ) ;
363355 }
356+
357+ let new_selected_commit =
358+ self . highlights . as_ref ( ) . and_then ( |highlights| {
359+ highlights. iter ( ) . nth ( new_index) . copied ( )
360+ } ) ;
361+
362+ if let Some ( c) = new_selected_commit {
363+ self . select_commit ( c) ?;
364+ return Ok ( true ) ;
365+ }
366+
367+ Ok ( false )
364368 }
365369
366370 fn move_selection_normal (
@@ -754,12 +758,15 @@ impl CommitList {
754758 . unwrap_or_default ( ) ;
755759
756760 if !index_in_sync || !self . is_list_in_sync ( ) || force {
757- let slice_end =
758- want_min. saturating_add ( SLICE_SIZE ) . min ( commits) ;
759-
760761 let commits = sync:: get_commits_info (
761762 & self . repo . borrow ( ) ,
762- & self . commits [ want_min..slice_end] ,
763+ self . commits
764+ . iter ( )
765+ . skip ( want_min)
766+ . take ( SLICE_SIZE )
767+ . copied ( )
768+ . collect_vec ( )
769+ . as_slice ( ) ,
763770 self . current_size ( )
764771 . map_or ( 100u16 , |size| size. 0 )
765772 . into ( ) ,
0 commit comments