]> granicus.if.org Git - neomutt/commitdiff
Fix sidebar pagedown/up when mailboxes on the end are hidden.
authorKevin McCarthy <kevin@8t8.us>
Sat, 9 Jul 2016 01:52:51 +0000 (18:52 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sat, 9 Jul 2016 01:52:51 +0000 (18:52 -0700)
The pageup/pagedown code was setting the highlighted mailbox to the
top and bottom index without checking if those were hidden.

sidebar.c

index 3a1bde7158df39a005548e0a61c0b897212d5813..e710b672736cc6d4925fb1129eca6465ca9cb968 100644 (file)
--- 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 ())