From 7c9548c6682d0628e109656021f504de619579de Mon Sep 17 00:00:00 2001 From: veeso Date: Sun, 21 Mar 2021 12:16:11 +0100 Subject: [PATCH] Prevent subtract with underflow --- src/ui/layout/components/file_list.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ui/layout/components/file_list.rs b/src/ui/layout/components/file_list.rs index 8801c6a..7a290f6 100644 --- a/src/ui/layout/components/file_list.rs +++ b/src/ui/layout/components/file_list.rs @@ -95,8 +95,10 @@ impl OwnStates { /// /// Keep index if possible, otherwise set to lenght - 1 pub fn fix_list_index(&mut self) { - if self.list_index >= self.list_len { + if self.list_index >= self.list_len && self.list_len > 0 { self.list_index = self.list_len - 1; + } else if self.list_len == 0 { + self.list_index = 0; } } }