mail/listing: go to end when pressing next/page down for the second time

When navigating the sidebar menu, if you reach the last account entry
and hit next account, nothing happens. This commit makes it so that
you're pointed to the last mailbox instead.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
fix/gitea-ci-artifacts
Manos Pitsidianakis 2023-09-14 15:08:44 +03:00
parent 7eed82783a
commit 22525d40fb
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
1 changed files with 18 additions and 2 deletions

View File

@ -1516,7 +1516,15 @@ impl Component for Listing {
};
match k {
k if shortcut!(k == shortcuts[Shortcuts::LISTING]["next_account"]) => {
if self.cursor_pos.account + amount < self.accounts.len() {
if self.cursor_pos.account + amount >= self.accounts.len() {
// Go to last mailbox.
self.cursor_pos.menu = MenuEntryCursor::Mailbox(
self.accounts[self.cursor_pos.account]
.entries
.len()
.saturating_sub(1),
);
} else if self.cursor_pos.account + amount < self.accounts.len() {
self.cursor_pos.account += amount;
self.cursor_pos.menu = MenuEntryCursor::Mailbox(0);
} else {
@ -2090,7 +2098,15 @@ impl Component for Listing {
k if shortcut!(k == shortcuts[Shortcuts::LISTING]["next_account"])
|| shortcut!(k == shortcuts[Shortcuts::LISTING]["next_page"]) =>
{
if self.menu_cursor_pos.account + amount < self.accounts.len() {
if self.menu_cursor_pos.account + amount >= self.accounts.len() {
// Go to last mailbox.
self.menu_cursor_pos.menu = MenuEntryCursor::Mailbox(
self.accounts[self.menu_cursor_pos.account]
.entries
.len()
.saturating_sub(1),
);
} else if self.menu_cursor_pos.account + amount < self.accounts.len() {
self.menu_cursor_pos.account += amount;
self.menu_cursor_pos.menu = MenuEntryCursor::Mailbox(0);
} else {