- int dcount = 0;
- int check;
-
- /* calculate the number of messages _above_ the cursor,
- * so we can keep the cursor on the current message
- */
- for (j = 0; j <= menu->current; j++)
- {
- if (Context->hdrs[Context->v2r[j]]->deleted)
- dcount++;
- }
+ int check, newidx;
+ HEADER *newhdr = NULL;
+
+ /* threads may be reordered, so figure out what header the cursor
+ * should be on. #3092 */
+ newidx = menu->current;
+ if (CURHDR->deleted)
+ newidx = ci_next_undeleted (menu->current);
+ if (newidx < 0)
+ newidx = ci_previous_undeleted (menu->current);
+ if (newidx >= 0)
+ newhdr = Context->hdrs[Context->v2r[newidx]];