Skip to content

Commit f54cbe9

Browse files
committed
Fix file history for all sizes
Replace temporary fix by proper fix
1 parent 5c98e2f commit f54cbe9

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

src/components/file_revlog.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ impl FileRevlogComponent {
152152
git_log.fetch()? == FetchStatus::Started;
153153

154154
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();
157156

158-
if self.items.needs_data(start, git_log.count()?)
157+
if self.items.needs_data(offset, git_log.count()?)
159158
|| log_changed
160159
{
161160
self.fetch_commits()?;
@@ -225,44 +224,18 @@ impl FileRevlogComponent {
225224
fn fetch_commits(&mut self) -> Result<()> {
226225
if let Some(git_log) = &mut self.git_log {
227226
let table_state = self.table_state.take();
227+
let offset = table_state.offset();
228228

229229
let commits = get_commits_info(
230230
&self.repo_path.borrow(),
231-
&git_log.get_slice(0, SLICE_SIZE)?,
231+
&git_log.get_slice(offset, SLICE_SIZE)?,
232232
self.current_width.get(),
233233
);
234234

235235
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);
263237
}
264238

265-
self.table_state.set(table_state);
266239
self.count_total = git_log.count()?;
267240
}
268241

@@ -374,6 +347,13 @@ impl FileRevlogComponent {
374347
self.queue.push(InternalEvent::Update(NeedsUpdate::DIFF));
375348
}
376349

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+
377357
table_state.select(Some(new_selection));
378358
self.table_state.set(table_state);
379359

0 commit comments

Comments
 (0)