diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index cef0e05ae..7882a1846 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -555,7 +555,7 @@ impl ListingTrait for CompactListing { } else if self.new_cursor_pos.2 + rows * multiplier > self.length { self.new_cursor_pos.2 = self.length - 1; } else { - self.new_cursor_pos.2 = (self.length / rows) * rows; + self.new_cursor_pos.2 = (self.length.saturating_sub(1) / rows) * rows; } } PageMovement::Right(_) | PageMovement::Left(_) => {} diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index edf5645a8..966bdac63 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -638,7 +638,7 @@ impl ListingTrait for ConversationsListing { } else if self.new_cursor_pos.2 + rows * multiplier > self.length { self.new_cursor_pos.2 = self.length - 1; } else { - self.new_cursor_pos.2 = (self.length / rows) * rows; + self.new_cursor_pos.2 = (self.length.saturating_sub(1) / rows) * rows; } } PageMovement::Right(_) | PageMovement::Left(_) => {} @@ -646,7 +646,7 @@ impl ListingTrait for ConversationsListing { self.new_cursor_pos.2 = 0; } PageMovement::End => { - self.new_cursor_pos.2 = self.length - 1; + self.new_cursor_pos.2 = self.length.saturating_sub(1); } } } diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index 5beda7049..e95001314 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -440,7 +440,7 @@ impl ListingTrait for PlainListing { } else if self.new_cursor_pos.2 + rows * multiplier > self.length { self.new_cursor_pos.2 = self.length - 1; } else { - self.new_cursor_pos.2 = (self.length / rows) * rows; + self.new_cursor_pos.2 = (self.length.saturating_sub(1) / rows) * rows; } } PageMovement::Right(_) | PageMovement::Left(_) => {} @@ -448,11 +448,7 @@ impl ListingTrait for PlainListing { self.new_cursor_pos.2 = 0; } PageMovement::End => { - if self.new_cursor_pos.2 + rows > self.length { - self.new_cursor_pos.2 = self.length - 1; - } else { - self.new_cursor_pos.2 = (self.length / rows) * rows; - } + self.new_cursor_pos.2 = self.length.saturating_sub(1); } } } diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index a0c4e5ead..6c34a5e0f 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -463,7 +463,7 @@ impl ListingTrait for ThreadListing { } else if self.new_cursor_pos.2 + rows * multiplier > self.length { self.new_cursor_pos.2 = self.length - 1; } else { - self.new_cursor_pos.2 = (self.length / rows) * rows; + self.new_cursor_pos.2 = (self.length.saturating_sub(1) / rows) * rows; } } PageMovement::Right(_) | PageMovement::Left(_) => {} @@ -471,7 +471,7 @@ impl ListingTrait for ThreadListing { self.new_cursor_pos.2 = 0; } PageMovement::End => { - self.new_cursor_pos.2 = self.length - 1; + self.new_cursor_pos.2 = self.length.saturating_sub(1); } } }