From 31e4ed006d6a56f372681a449dc8a5aefe62f0b7 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 23 Nov 2020 06:53:09 +0200 Subject: [PATCH] listing: fix off by one error in PageDown movement --- src/components/mail/listing/compact.rs | 2 +- src/components/mail/listing/conversations.rs | 4 ++-- src/components/mail/listing/plain.rs | 8 ++------ src/components/mail/listing/thread.rs | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index cef0e05a..7882a184 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 edf5645a..966bdac6 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 5beda704..e9500131 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 a0c4e5ea..6c34a5e0 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); } } }