2 This is the sensible browser position patch by Haakon Riiser.
4 * Found in: <20050309162127.GA5656@s>
5 http://lists.df7cb.de/mutt/message/20050309.162127.a244a894.en.html
12 int mutt_menuLoop (MUTTMENU *menu)
14 + static int last_position = -1;
17 + if ( menu->max && menu->is_mailbox_list ) {
18 + if ( last_position > (menu->max-1) ) {
20 + } else if (last_position >= 0) {
21 + menu->current = last_position;
27 if (option (OPTMENUCALLER))
32 + if (menu->is_mailbox_list)
33 + last_position = menu->current;
43 +static char OldLastDir[_POSIX_PATH_MAX] = "";
44 static char LastDir[_POSIX_PATH_MAX] = "";
45 static char LastDirBackup[_POSIX_PATH_MAX] = "";
52 + menu->is_mailbox_list = 1;
53 snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
57 + menu->is_mailbox_list = 0;
58 strfcpy (path, LastDir, sizeof (path));
59 mutt_pretty_mailbox (path, sizeof (path));
62 path, NONULL (Mask.pattern));
65 - snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
66 - path, NONULL(Mask.pattern));
68 + char *p = strrchr (OldLastDir, '/');
69 + if (p && p - OldLastDir == mutt_strlen (LastDir) &&
70 + mutt_strncmp (LastDir, OldLastDir, p - OldLastDir) == 0)
72 + /* If we get here, it means that LastDir is the parent directory of
73 + * OldLastDir. I.e., we're returning from a subdirectory, and we want
74 + * to position the cursor on the directory we're returning from. */
76 + for (i = 0; i < state->entrymax; i++)
77 + if (mutt_strcmp (state->entry[i].name, p + 1) == 0)
80 + snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
81 + path, NONULL(Mask.pattern));
84 menu->redraw = REDRAW_FULL;
90 - char OldLastDir[_POSIX_PATH_MAX];
92 /* save the old directory */
93 strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
97 int offset; /* which screen row to start the index */
98 int pagelen; /* number of entries per screen */
100 + int is_mailbox_list;
102 /* Setting dialog != NULL overrides normal menu behaviour.
103 * In dialog mode menubar is hidden and prompt keys are checked before