Skip to content

Commit

Permalink
bugfix: fix crash when first index selected in findcard
Browse files Browse the repository at this point in the history
  • Loading branch information
TBS1996 committed Nov 2, 2022
1 parent 177c318 commit 11fd2b3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
21 changes: 20 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl TabsState {
}
}
fn render(&mut self, f: &mut Frame<MyType>, appdata: &AppData, area: Rect) {
self.tabs[self.index].render(f, appdata, area);
self.tabs[self.index].main_render(f, appdata, area);
}
}

Expand Down Expand Up @@ -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<MyType>, 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<dyn PopUp>> {
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")
}
}
16 changes: 10 additions & 6 deletions src/tabs/review/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn PopUp>> {
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
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/widgets/find_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 11fd2b3

Please sign in to comment.