@@ -77,18 +77,23 @@ impl LogEntry {
7777///
7878#[ derive( Default ) ]
7979pub struct ItemBatch {
80- index_offset : usize ,
80+ index_offset : Option < usize > ,
8181 items : Vec < LogEntry > ,
8282 highlighting : bool ,
8383}
8484
8585impl ItemBatch {
8686 fn last_idx ( & self ) -> usize {
87- self . index_offset + self . items . len ( )
87+ self . index_offset ( ) + self . items . len ( )
8888 }
8989
9090 ///
91- pub const fn index_offset ( & self ) -> usize {
91+ pub fn index_offset ( & self ) -> usize {
92+ self . index_offset . unwrap_or_default ( )
93+ }
94+
95+ ///
96+ pub const fn index_offset_raw ( & self ) -> Option < usize > {
9297 self . index_offset
9398 }
9499
@@ -105,6 +110,7 @@ impl ItemBatch {
105110 /// clear curent list of items
106111 pub fn clear ( & mut self ) {
107112 self . items . clear ( ) ;
113+ self . index_offset = None ;
108114 }
109115
110116 /// insert new batch of items
@@ -114,21 +120,25 @@ impl ItemBatch {
114120 commits : Vec < CommitInfo > ,
115121 highlighted : & Option < Rc < IndexSet < CommitId > > > ,
116122 ) {
117- self . items . clear ( ) ;
118- self . items . extend ( commits. into_iter ( ) . map ( |c| {
119- let id = c. id ;
120- let mut entry = LogEntry :: from ( c) ;
121- if highlighted
122- . as_ref ( )
123- . map ( |highlighted| highlighted. contains ( & id) )
124- . unwrap_or_default ( )
125- {
126- entry. highlighted = true ;
127- }
128- entry
129- } ) ) ;
130- self . highlighting = highlighted. is_some ( ) ;
131- self . index_offset = start_index;
123+ self . clear ( ) ;
124+
125+ if !commits. is_empty ( ) {
126+ self . items . extend ( commits. into_iter ( ) . map ( |c| {
127+ let id = c. id ;
128+ let mut entry = LogEntry :: from ( c) ;
129+ if highlighted
130+ . as_ref ( )
131+ . map ( |highlighted| highlighted. contains ( & id) )
132+ . unwrap_or_default ( )
133+ {
134+ entry. highlighted = true ;
135+ }
136+ entry
137+ } ) ) ;
138+
139+ self . index_offset = Some ( start_index) ;
140+ self . highlighting = highlighted. is_some ( ) ;
141+ }
132142 }
133143
134144 /// returns `true` if we should fetch updated list of items
@@ -139,7 +149,7 @@ impl ItemBatch {
139149 . saturating_add ( SLICE_OFFSET_RELOAD_THRESHOLD )
140150 . min ( idx_max) ;
141151
142- let needs_data_top = want_min < self . index_offset ;
152+ let needs_data_top = want_min < self . index_offset ( ) ;
143153 let needs_data_bottom = want_max >= self . last_idx ( ) ;
144154 needs_data_bottom || needs_data_top
145155 }
0 commit comments