diff --git a/Cargo.lock b/Cargo.lock index 14ca1fb..62dbaac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2419,7 +2419,7 @@ dependencies = [ [[package]] name = "speki" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 45f55f4..da8a67c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "speki" -version = "0.4.1" +version = "0.4.2" edition = "2021" authors = ["Tor Berge torberge@outlook.com"] license = "GPL-2.0-only" diff --git a/src/app.rs b/src/app.rs index 3a92d2b..478aa28 100644 --- a/src/app.rs +++ b/src/app.rs @@ -118,7 +118,7 @@ impl TabsState { } } fn render(&mut self, f: &mut Frame, appdata: &AppData, area: Rect) { - self.tabs[self.index].render(f, appdata, area); + self.tabs[self.index].main_render(f, appdata, area); } } @@ -286,4 +286,23 @@ pub trait Tab { fn set_selection(&mut self, area: Rect); fn get_cursor(&self) -> (u16, u16); fn navigate(&mut self, dir: NavDir); + + fn main_render(&mut self, f: &mut Frame, appdata: &AppData, area: Rect) { + self.render(f, appdata, area); + if let Some(popup) = self.get_popup() { + if popup.should_quit() { + self.exit_popup(appdata); + return; + } + popup.render_popup(f, appdata, area); + } + } + fn get_popup(&mut self) -> Option<&mut Box> { + None + } + fn exit_popup(&mut self, appdata: &AppData) { + let _ = appdata; + // if there's a way to statically enforce this requirement, make an issue or PR about it <3 + panic!("Overriding the get_popup() method requires you to also override the exit_popup() method") + } } diff --git a/src/tabs/review/logic.rs b/src/tabs/review/logic.rs index 368820f..0895ce2 100644 --- a/src/tabs/review/logic.rs +++ b/src/tabs/review/logic.rs @@ -404,14 +404,18 @@ impl Tab for MainReview { ReviewMode::Unfinished(unfinished) => unfinished.render(f, appdata, cursor), ReviewMode::IncRead(inc) => inc.render(f, appdata, cursor), } + } + + fn exit_popup(&mut self, appdata: &AppData) { + self.popup = None; + self.update_dependencies(&appdata.conn); + } + fn get_popup(&mut self) -> Option<&mut Box> { if let Some(popup) = &mut self.popup { - if popup.should_quit() { - self.popup = None; - self.update_dependencies(&appdata.conn); - return; - } - popup.render_popup(f, appdata, area); + Some(popup) + } else { + None } } diff --git a/src/widgets/find_card.rs b/src/widgets/find_card.rs index b669b74..61489ec 100644 --- a/src/widgets/find_card.rs +++ b/src/widgets/find_card.rs @@ -70,9 +70,12 @@ impl FindCardWidget { if self.list.state.selected().is_none() { return; } + if self.list.items.is_empty() { + return; + } let idx = self.list.state.selected().unwrap(); - if idx - 1 > self.list.items.len() { + if idx >= self.list.items.len() { return; } let chosen_id = self.list.items[idx].id;