I would like some feedback on this patch.  Please read the patch summary
for details.

Once in a blue moon, I open a new message, and it opens scrolled partway
down.  This annoyed me enough to put on my todo list to dig into, which
I finally took some time to do.

I believe this is because the Header pointer happens to match the OldHdr
pointer saved in the pager.

This patch restricts the position-saving to operations that redirect
back to the same message only.

It *does* cause some minor changes in behavior, so I would appreciate
feedback.  I consider the original behavior a mistake, but recognize
others may feel differently.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
# HG changeset patch
# User Kevin McCarthy <ke...@8t8.us>
# Date 1470520308 25200
#      Sat Aug 06 14:51:48 2016 -0700
# Node ID c441a71c204ebad45d0144f71df539d46108815e
# Parent  108ad5dcf19435dd8c1d940e8695afcf301f8ceb
Preserve pager position only for ops that redirect back to the same message.

The easiest way to trigger this is to open a long message in a mailbox
with no new messages, scroll down, hit <next-new-then-unread> and then
reopen the message.  The pager will "remember" the position and scroll
down.  If you simply exit the message and re-enter it, the position is
not saved.

More annoyingly, once in a very great while I will open a new message
and have the message scrolled down partway.  I believe this is due to
OldHdr happening to point to the same address as the Header of the new
message.

This is somewhat easily triggered on a mailbox with one message, which
you open, scroll down in, hit <next-new-then-unread> to exit, and then
delete/sync.  In another mutt instance, copy the same messsage back to
the mailbox, then open the message in the original mutt instance.  At
least some of the time, the OldHdr pointer matches the new message,
and so it opens scrolled down.

This patch saves the pager position only for operations that redirect
back to the pager with the same message.

diff --git a/curs_main.c b/curs_main.c
--- a/curs_main.c
+++ b/curs_main.c
@@ -2366,16 +2366,17 @@
 #endif
       default:
        if (menu->menu == MENU_MAIN)
          km_error_key (MENU_MAIN);
     }
 
     if (menu->menu == MENU_PAGER)
     {
+      mutt_clear_pager_position ();
       menu->menu = MENU_MAIN;
       menu->redraw = REDRAW_FULL;
 #if 0
       set_option (OPTWEED); /* turn header weeding back on. */
 #endif
     }
 
     if (done) break;
diff --git a/pager.c b/pager.c
--- a/pager.c
+++ b/pager.c
@@ -1558,16 +1558,21 @@
 static const struct mapping_t PagerHelpExtra[] = {
   { N_("View Attachm."), OP_VIEW_ATTACHMENTS },
   { N_("Del"), OP_DELETE },
   { N_("Reply"), OP_REPLY },
   { N_("Next"),        OP_MAIN_NEXT_UNDELETED },
   { NULL,      0 }
 };
 
+void mutt_clear_pager_position (void)
+{
+  TopLine = 0;
+  OldHdr = NULL;
+}
 
 
 /* This pager is actually not so simple as it once was.  It now operates in
    two modes: one for viewing messages and the other for viewing help.  These
    can be distinguished by whether or not ``hdr'' is NULL.  The ``hdr'' arg
    is there so that we can do operations on the current message without the
    need to pop back out to the main-menu.  */
 int 
@@ -2857,22 +2862,42 @@
        break;
     }
   }
 
   safe_fclose (&fp);
   if (IsHeader (extra))
   {
     Context->msgnotreadyet = -1;
-    if (rc == -1)
-      OldHdr = NULL;
-    else
+
+    switch (rc)
     {
-      TopLine = topline;
-      OldHdr = extra->hdr;
+      /* These operations are handled by the index and are then
+       * redirected back to the same message in the pager: */
+      case OP_SORT:
+      case OP_SORT_REVERSE:
+      case OP_MAIN_SYNC_FOLDER:
+      case OP_DISPLAY_HEADERS:
+      case OP_MAIN_BREAK_THREAD:
+      case OP_MAIN_LINK_THREADS:
+      case OP_EDIT_TYPE:
+      case OP_CHECK_TRADITIONAL:
+
+      /* These two redirect back if they abort entering the folder name: */
+      case OP_MAIN_CHANGE_FOLDER:
+      case OP_MAIN_CHANGE_FOLDER_READONLY:
+        TopLine = topline;
+        OldHdr = extra->hdr;
+        break;
+
+      /* All other operations do not redirect back to the same message in
+       * the pager. */
+      default:
+        mutt_clear_pager_position ();
+        break;
     }
   }
     
   cleanup_quote (&QuoteList);
   
   for (i = 0; i < maxLine ; i++)
   {
     FREE (&(lineInfo[i].syntax));
diff --git a/protos.h b/protos.h
--- a/protos.h
+++ b/protos.h
@@ -170,16 +170,17 @@
 int  mutt_bounce_message (FILE *fp, HEADER *, ADDRESS *);
 void mutt_break_thread (HEADER *);
 void mutt_buffy (char *, size_t);
 int  mutt_buffy_list (void);
 void mutt_canonical_charset (char *, size_t, const char *);
 int mutt_count_body_parts (CONTEXT *, HEADER *);
 void mutt_check_rescore (CONTEXT *);
 void mutt_clear_error (void);
+void mutt_clear_pager_position (void);
 void mutt_create_alias (ENVELOPE *, ADDRESS *);
 void mutt_decode_attachment (BODY *, STATE *);
 void mutt_decode_base64 (STATE *s, long len, int istext, iconv_t cd);
 void mutt_default_save (char *, size_t, HEADER *);
 void mutt_display_address (ENVELOPE *);
 void mutt_display_sanitize (char *);
 void mutt_edit_content_type (HEADER *, BODY *, FILE *);
 void mutt_edit_file (const char *, const char *);

Attachment: signature.asc
Description: PGP signature

Reply via email to