@@ -44,7 +44,7 @@ pub struct CommitList {
44
44
highlighted_selection : Option < usize > ,
45
45
items : ItemBatch ,
46
46
highlights : Option < Rc < IndexSet < CommitId > > > ,
47
- commits : Vec < CommitId > ,
47
+ commits : IndexSet < CommitId > ,
48
48
marked : Vec < ( usize , CommitId ) > ,
49
49
scroll_state : ( Instant , f32 ) ,
50
50
tags : Option < Tags > ,
@@ -72,7 +72,7 @@ impl CommitList {
72
72
marked : Vec :: with_capacity ( 2 ) ,
73
73
selection : 0 ,
74
74
highlighted_selection : None ,
75
- commits : Vec :: new ( ) ,
75
+ commits : IndexSet :: new ( ) ,
76
76
highlights : None ,
77
77
scroll_state : ( Instant :: now ( ) , 0_f32 ) ,
78
78
tags : None ,
@@ -100,7 +100,7 @@ impl CommitList {
100
100
101
101
///
102
102
pub fn copy_items ( & self ) -> Vec < CommitId > {
103
- self . commits . clone ( )
103
+ self . commits . iter ( ) . copied ( ) . collect_vec ( )
104
104
}
105
105
106
106
///
@@ -224,7 +224,7 @@ impl CommitList {
224
224
}
225
225
226
226
///
227
- pub fn set_commits ( & mut self , commits : Vec < CommitId > ) {
227
+ pub fn set_commits ( & mut self , commits : IndexSet < CommitId > ) {
228
228
if commits != self . commits {
229
229
self . items . clear ( ) ;
230
230
self . commits = commits;
@@ -268,10 +268,10 @@ impl CommitList {
268
268
269
269
///
270
270
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) ;
272
272
273
- if let Some ( position ) = position {
274
- self . selection = position ;
273
+ if let Some ( index ) = index {
274
+ self . selection = index ;
275
275
self . set_highlighted_selection_index ( ) ;
276
276
Ok ( ( ) )
277
277
} else {
@@ -332,35 +332,39 @@ impl CommitList {
332
332
& mut self ,
333
333
scroll : ScrollType ,
334
334
) -> Result < bool > {
335
- let old_selection = self . selection ;
335
+ let ( current_index, selection_max) =
336
+ self . highlighted_selection_info ( ) ;
336
337
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 ) ,
347
341
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
+ } ;
351
347
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 ) ) ;
356
350
357
- self . selection = new_selection ;
351
+ let index_changed = new_index != current_index ;
358
352
359
- if self . selection_highlighted ( ) {
360
- self . set_highlighted_selection_index ( ) ;
361
- return Ok ( true ) ;
362
- }
353
+ if !index_changed {
354
+ return Ok ( false ) ;
363
355
}
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 )
364
368
}
365
369
366
370
fn move_selection_normal (
@@ -754,12 +758,15 @@ impl CommitList {
754
758
. unwrap_or_default ( ) ;
755
759
756
760
if !index_in_sync || !self . is_list_in_sync ( ) || force {
757
- let slice_end =
758
- want_min. saturating_add ( SLICE_SIZE ) . min ( commits) ;
759
-
760
761
let commits = sync:: get_commits_info (
761
762
& 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 ( ) ,
763
770
self . current_size ( )
764
771
. map_or ( 100u16 , |size| size. 0 )
765
772
. into ( ) ,
0 commit comments