]> granicus.if.org Git - neomutt/commitdiff
Fix the sidebar TopIndex and BotIndex when $sidebar_new_mail_only is set.
authorKevin McCarthy <kevin@8t8.us>
Thu, 7 Jul 2016 19:00:37 +0000 (12:00 -0700)
committerKevin McCarthy <kevin@8t8.us>
Thu, 7 Jul 2016 19:00:37 +0000 (12:00 -0700)
When set, some of the entries can be hidden, so a simple division by
page_size to find the correct top/bottom isn't correct.

Instead, manually partition into groups of page_size visible entries
and set top and bottom based on the interval around the highlighted
entry.

sidebar.c

index 3c2d9c03e51d15cc22bdcea67fb34ccf6ab86d32..3a1bde7158df39a005548e0a61c0b897212d5813 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -50,6 +50,9 @@ static int OpnIndex = -1;    /* Current (open) mailbox */
 static int HilIndex = -1;    /* Highlighted mailbox */
 static int BotIndex = -1;    /* Last mailbox visible in sidebar */
 
+static int select_next (void);
+
+
 /**
  * cb_format_str - Create the string to show in the sidebar
  * @dest:        Buffer in which to save string
@@ -386,8 +389,9 @@ static int prepare_sidebar (int page_size)
 {
   int i;
   SBENTRY *opn_entry = NULL, *hil_entry = NULL;
+  int page_entries;
 
-  if (!EntryCount)
+  if (!EntryCount || (page_size <= 0))
     return 0;
 
   if (OpnIndex >= 0)
@@ -409,16 +413,43 @@ static int prepare_sidebar (int page_size)
   if ((HilIndex < 0) || (SidebarSortMethod != PreviousSort))
   {
     if (OpnIndex >= 0)
-      HilIndex  = OpnIndex;
+      HilIndex = OpnIndex;
     else
-      HilIndex  = 0;
+    {
+      HilIndex = 0;
+      if (Entries[HilIndex]->is_hidden)
+        select_next ();
+    }
   }
-  if (TopIndex >= 0)
-    TopIndex = (HilIndex / page_size) * page_size;
+
+  /* Set the Top and Bottom to frame the HilIndex in groups of page_size */
+
+  /* If OPTSIDEBARNEMAILONLY is set, some entries may be hidden so we
+   * need to scan for the framing interval */
+  if (option (OPTSIDEBARNEWMAILONLY))
+  {
+    TopIndex = BotIndex = -1;
+    while (BotIndex < HilIndex)
+    {
+      TopIndex = BotIndex + 1;
+      page_entries = 0;
+      while (page_entries < page_size)
+      {
+        BotIndex++;
+        if (BotIndex >= EntryCount)
+          break;
+        if (! Entries[BotIndex]->is_hidden)
+          page_entries++;
+      }
+    }
+  }
+  /* Otherwise we can just calculate the interval */
   else
-    TopIndex = HilIndex;
+  {
+    TopIndex = (HilIndex / page_size) * page_size;
+    BotIndex = TopIndex + page_size - 1;
+  }
 
-  BotIndex = TopIndex + page_size - 1;
   if (BotIndex > (EntryCount - 1))
     BotIndex = EntryCount - 1;