@@ -152,10 +152,9 @@ impl FileRevlogComponent {
152
152
git_log. fetch ( ) ? == FetchStatus :: Started ;
153
153
154
154
let table_state = self . table_state . take ( ) ;
155
- let start = table_state. selected ( ) . unwrap_or ( 0 ) ;
156
- self . table_state . set ( table_state) ;
155
+ let offset = table_state. offset ( ) ;
157
156
158
- if self . items . needs_data ( start , git_log. count ( ) ?)
157
+ if self . items . needs_data ( offset , git_log. count ( ) ?)
159
158
|| log_changed
160
159
{
161
160
self . fetch_commits ( ) ?;
@@ -225,44 +224,18 @@ impl FileRevlogComponent {
225
224
fn fetch_commits ( & mut self ) -> Result < ( ) > {
226
225
if let Some ( git_log) = & mut self . git_log {
227
226
let table_state = self . table_state . take ( ) ;
227
+ let offset = table_state. offset ( ) ;
228
228
229
229
let commits = get_commits_info (
230
230
& self . repo_path . borrow ( ) ,
231
- & git_log. get_slice ( 0 , SLICE_SIZE ) ?,
231
+ & git_log. get_slice ( offset , SLICE_SIZE ) ?,
232
232
self . current_width . get ( ) ,
233
233
) ;
234
234
235
235
if let Ok ( commits) = commits {
236
- // 2023-04-12
237
- //
238
- // There is an issue with how windowing works in `self.items` and
239
- // `self.table_state`. Because of that issue, we currently have to pass
240
- // `0` as the first argument to `set_items`. If we did not do that, the
241
- // offset that is kept separately in `self.items` and `self.table_state`
242
- // would get out of sync, resulting in the table showing the wrong rows.
243
- //
244
- // The offset determines the number of rows `render_stateful_widget`
245
- // skips when rendering a table. When `set_items` is called, it clears
246
- // its internal `Vec` of items and sets `index_offset` based on the
247
- // parameter passed. Unfortunately, there is no way for us to pass this
248
- // information, `index_offset`, to `render_stateful_widget`. Because of
249
- // that, `render_stateful_widget` assumes that the rows provided by
250
- // `Table` are 0-indexed while in reality they are
251
- // `index_offset`-indexed.
252
- //
253
- // This fix makes the `FileRevlog` unable to show histories that have
254
- // more than `SLICE_SIZE` items, but since it is broken for larger
255
- // histories anyway, this seems acceptable for the time being.
256
- //
257
- // This issue can only properly be fixed upstream, in `tui-rs`. See
258
- // [tui-issue].
259
- //
260
- // [gitui-issue]: https://github.com/extrawurst/gitui/issues/1560
261
- // [tui-issue]: https://github.com/fdehau/tui-rs/issues/626
262
- self . items . set_items ( 0 , commits) ;
236
+ self . items . set_items ( offset, commits) ;
263
237
}
264
238
265
- self . table_state . set ( table_state) ;
266
239
self . count_total = git_log. count ( ) ?;
267
240
}
268
241
@@ -374,6 +347,13 @@ impl FileRevlogComponent {
374
347
self . queue . push ( InternalEvent :: Update ( NeedsUpdate :: DIFF ) ) ;
375
348
}
376
349
350
+ let height_in_items = self . current_height . get ( ) / 2 ;
351
+ let new_offset =
352
+ new_selection. saturating_sub ( height_in_items) ;
353
+
354
+ let offset = table_state. offset_mut ( ) ;
355
+ * offset = new_offset;
356
+
377
357
table_state. select ( Some ( new_selection) ) ;
378
358
self . table_state . set ( table_state) ;
379
359
0 commit comments