changeset: 6719:5fb53b95afa7 user: Kevin McCarthy <ke...@8t8.us> date: Fri Jul 08 18:52:51 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/5fb53b95afa7
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. changeset: 6720:ec4c113a3d2b user: Kevin McCarthy <ke...@8t8.us> date: Fri Jul 08 18:52:56 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/ec4c113a3d2b Change sidebar highlighted mailbox behavior. Delay selecting the highlighted mailbox until prepare_mailbox(), to avoid a hidden mailbox being selected during the Buffy list population (in mutt_sb_notify_mailbox()). Change update_entries_visibility() to not automatically make the highlighted mailbox visible. Change prepare_sidebar() to (re)set the highlighted mailbox when the current highlighted mailbox is hidden. diffs (101 lines): diff -r 4dc1831fd6d7 -r ec4c113a3d2b sidebar.c --- a/sidebar.c Fri Jul 08 18:47:57 2016 -0700 +++ b/sidebar.c Fri Jul 08 18:52:56 2016 -0700 @@ -303,7 +303,7 @@ continue; if ((i == OpnIndex) || (sbe->buffy->msg_unread > 0) || sbe->buffy->new || - (i == HilIndex) || (sbe->buffy->msg_flagged > 0)) + (sbe->buffy->msg_flagged > 0)) continue; if (Context && (mutt_strcmp (sbe->buffy->realpath, Context->realpath) == 0)) @@ -410,7 +410,8 @@ HilIndex = i; } - if ((HilIndex < 0) || (SidebarSortMethod != PreviousSort)) + if ((HilIndex < 0) || Entries[HilIndex]->is_hidden || + (SidebarSortMethod != PreviousSort)) { if (OpnIndex >= 0) HilIndex = OpnIndex; @@ -805,6 +806,52 @@ } /** + * 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 +885,12 @@ 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 ()) @@ -962,8 +1009,6 @@ if (TopIndex < 0) TopIndex = EntryCount; - if (HilIndex < 0) - HilIndex = EntryCount; if (BotIndex < 0) BotIndex = EntryCount; if ((OpnIndex < 0) && Context &&