@@ -77,18 +77,23 @@ impl LogEntry {
77
77
///
78
78
#[ derive( Default ) ]
79
79
pub struct ItemBatch {
80
- index_offset : usize ,
80
+ index_offset : Option < usize > ,
81
81
items : Vec < LogEntry > ,
82
82
highlighting : bool ,
83
83
}
84
84
85
85
impl ItemBatch {
86
86
fn last_idx ( & self ) -> usize {
87
- self . index_offset + self . items . len ( )
87
+ self . index_offset ( ) + self . items . len ( )
88
88
}
89
89
90
90
///
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 > {
92
97
self . index_offset
93
98
}
94
99
@@ -105,6 +110,7 @@ impl ItemBatch {
105
110
/// clear curent list of items
106
111
pub fn clear ( & mut self ) {
107
112
self . items . clear ( ) ;
113
+ self . index_offset = None ;
108
114
}
109
115
110
116
/// insert new batch of items
@@ -114,21 +120,25 @@ impl ItemBatch {
114
120
commits : Vec < CommitInfo > ,
115
121
highlighted : & Option < Rc < IndexSet < CommitId > > > ,
116
122
) {
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
+ }
132
142
}
133
143
134
144
/// returns `true` if we should fetch updated list of items
@@ -139,7 +149,7 @@ impl ItemBatch {
139
149
. saturating_add ( SLICE_OFFSET_RELOAD_THRESHOLD )
140
150
. min ( idx_max) ;
141
151
142
- let needs_data_top = want_min < self . index_offset ;
152
+ let needs_data_top = want_min < self . index_offset ( ) ;
143
153
let needs_data_bottom = want_max >= self . last_idx ( ) ;
144
154
needs_data_bottom || needs_data_top
145
155
}
0 commit comments