From 1428ced92335f6d30011aacba8c0f652715e24c4 Mon Sep 17 00:00:00 2001 From: kageru Date: Sat, 25 Jan 2020 15:49:54 +0100 Subject: [PATCH] Fix panic when deleting the last item --- src/todolist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/todolist.rs b/src/todolist.rs index 774985a..514855b 100644 --- a/src/todolist.rs +++ b/src/todolist.rs @@ -71,7 +71,7 @@ impl TodoList { return None; } let index = self.selected; - self.selected = index.min(self.todos.len() - 2); + self.selected = index.min(self.todos.len().saturating_sub(2)); return Some(self.todos.remove(index)); }