listing: fix off by one error in PageDown movement

This commit is contained in:
Manos Pitsidianakis 2020-11-23 06:53:09 +02:00
parent 179ed52add
commit 31e4ed006d
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710
4 changed files with 7 additions and 11 deletions

View File

@ -555,7 +555,7 @@ impl ListingTrait for CompactListing {
} else if self.new_cursor_pos.2 + rows * multiplier > self.length { } else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1; self.new_cursor_pos.2 = self.length - 1;
} else { } 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(_) => {} PageMovement::Right(_) | PageMovement::Left(_) => {}

View File

@ -638,7 +638,7 @@ impl ListingTrait for ConversationsListing {
} else if self.new_cursor_pos.2 + rows * multiplier > self.length { } else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1; self.new_cursor_pos.2 = self.length - 1;
} else { } 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(_) => {} PageMovement::Right(_) | PageMovement::Left(_) => {}
@ -646,7 +646,7 @@ impl ListingTrait for ConversationsListing {
self.new_cursor_pos.2 = 0; self.new_cursor_pos.2 = 0;
} }
PageMovement::End => { PageMovement::End => {
self.new_cursor_pos.2 = self.length - 1; self.new_cursor_pos.2 = self.length.saturating_sub(1);
} }
} }
} }

View File

@ -440,7 +440,7 @@ impl ListingTrait for PlainListing {
} else if self.new_cursor_pos.2 + rows * multiplier > self.length { } else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1; self.new_cursor_pos.2 = self.length - 1;
} else { } 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(_) => {} PageMovement::Right(_) | PageMovement::Left(_) => {}
@ -448,11 +448,7 @@ impl ListingTrait for PlainListing {
self.new_cursor_pos.2 = 0; self.new_cursor_pos.2 = 0;
} }
PageMovement::End => { PageMovement::End => {
if self.new_cursor_pos.2 + rows > self.length { self.new_cursor_pos.2 = self.length.saturating_sub(1);
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
} }
} }
} }

View File

@ -463,7 +463,7 @@ impl ListingTrait for ThreadListing {
} else if self.new_cursor_pos.2 + rows * multiplier > self.length { } else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1; self.new_cursor_pos.2 = self.length - 1;
} else { } 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(_) => {} PageMovement::Right(_) | PageMovement::Left(_) => {}
@ -471,7 +471,7 @@ impl ListingTrait for ThreadListing {
self.new_cursor_pos.2 = 0; self.new_cursor_pos.2 = 0;
} }
PageMovement::End => { PageMovement::End => {
self.new_cursor_pos.2 = self.length - 1; self.new_cursor_pos.2 = self.length.saturating_sub(1);
} }
} }
} }