From: Kevin McCarthy Date: Sat, 9 Jul 2016 01:52:51 +0000 (-0700) Subject: Fix sidebar pagedown/up when mailboxes on the end are hidden. X-Git-Tag: neomutt-20160822~83 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f54e8fac5092ba3a4412a945c06827eb891ebd9;p=neomutt Fix sidebar pagedown/up when mailboxes on the end are hidden. The pageup/pagedown code was setting the highlighted mailbox to the top and bottom index without checking if those were hidden. --- diff --git a/sidebar.c b/sidebar.c index 3a1bde715..e710b6727 100644 --- a/sidebar.c +++ b/sidebar.c @@ -804,6 +804,52 @@ static int select_prev_new (void) return 1; } +/** + * select_page_down - Selects the first entry in the next page of mailboxes + * + * Returns: + * 1: Success + * 0: Failure + */ +static int select_page_down (void) +{ + int orig_hil_index = HilIndex; + + if (!EntryCount || BotIndex < 0) + return 0; + + HilIndex = BotIndex; + select_next (); + /* If the rest of the entries are hidden, go up to the last unhidden one */ + if (Entries[HilIndex]->is_hidden) + select_prev (); + + return (orig_hil_index != HilIndex); +} + +/** + * select_page_up - Selects the last entry in the previous page of mailboxes + * + * Returns: + * 1: Success + * 0: Failure + */ +static int select_page_up (void) +{ + int orig_hil_index = HilIndex; + + if (!EntryCount || TopIndex < 0) + return 0; + + HilIndex = TopIndex; + select_prev (); + /* If the rest of the entries are hidden, go down to the last unhidden one */ + if (Entries[HilIndex]->is_hidden) + select_next (); + + return (orig_hil_index != HilIndex); +} + /** * mutt_sb_change_mailbox - Change the selected mailbox * @op: Operation code @@ -838,12 +884,12 @@ void mutt_sb_change_mailbox (int op) return; break; case OP_SIDEBAR_PAGE_DOWN: - HilIndex = BotIndex; - select_next (); + if (! select_page_down ()) + return; break; case OP_SIDEBAR_PAGE_UP: - HilIndex = TopIndex; - select_prev (); + if (! select_page_up ()) + return; break; case OP_SIDEBAR_PREV: if (! select_prev ())