From 4f01ef783c28904ddc7bcb71b99b73ac3e8fe41f Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sat, 23 May 2020 13:50:37 +0200 Subject: [PATCH] fix log not being updated after commit --- src/tabs/revlog/mod.rs | 6 +++--- src/tabs/revlog/utils.rs | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/tabs/revlog/mod.rs b/src/tabs/revlog/mod.rs index 5589d9d3..9272b99a 100644 --- a/src/tabs/revlog/mod.rs +++ b/src/tabs/revlog/mod.rs @@ -213,7 +213,6 @@ impl Revlog { let mut txt = Vec::new(); for (idx, e) in self - .items .items .iter() .skip(self.scroll_top) @@ -238,7 +237,7 @@ impl Revlog { } fn relative_selection(&self) -> usize { - self.selection.saturating_sub(self.items.index_offset) + self.selection.saturating_sub(self.items.index_offset()) } } @@ -346,6 +345,7 @@ impl Component for Revlog { fn show(&mut self) { self.visible = true; - self.git_log.fetch().unwrap(); + self.items.clear(); + self.update(); } } diff --git a/src/tabs/revlog/utils.rs b/src/tabs/revlog/utils.rs index d305b988..73b815a0 100644 --- a/src/tabs/revlog/utils.rs +++ b/src/tabs/revlog/utils.rs @@ -1,5 +1,6 @@ use asyncgit::sync::CommitInfo; use chrono::prelude::*; +use std::slice::Iter; static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100; @@ -30,8 +31,8 @@ impl From for LogEntry { /// #[derive(Default)] pub(super) struct ItemBatch { - pub index_offset: usize, - pub items: Vec, + index_offset: usize, + items: Vec, } impl ItemBatch { @@ -39,6 +40,22 @@ impl ItemBatch { self.index_offset + self.items.len() } + /// + pub fn index_offset(&self) -> usize { + self.index_offset + } + + /// shortcut to get an `Iter` of our internal items + pub fn iter(&self) -> Iter<'_, LogEntry> { + self.items.iter() + } + + /// clear curent list of items + pub fn clear(&mut self) { + self.items.clear(); + } + + /// insert new batch of items pub fn set_items( &mut self, start_index: usize, @@ -49,6 +66,7 @@ impl ItemBatch { self.index_offset = start_index; } + /// returns `true` if we should fetch updated list of items pub fn needs_data(&self, idx: usize, idx_max: usize) -> bool { let want_min = idx.saturating_sub(SLICE_OFFSET_RELOAD_THRESHOLD);