X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=menu.c;h=35a49879fd7b67a19dd89f97a93b5f2eb09697b5;hp=2243919c2ee6b85a9d66ec49042e1ac9e734b3a5;hb=f404a0ca916be07049af51a3022baaaaab94def6;hpb=3d937534e7b1ee723f86594b5e4c64c95158a933 diff --git a/menu.c b/menu.c index 2243919..35a4987 100644 --- a/menu.c +++ b/menu.c @@ -16,6 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include "mutt.h" #include "mutt_curses.h" #include "mutt_menu.h" @@ -366,32 +370,37 @@ void menu_redraw_prompt (MUTTMENU *menu) void menu_check_recenter (MUTTMENU *menu) { - if (menu->max <= menu->pagelen && menu->top != 0) + int c = MIN (MenuContext, menu->pagelen / 2); + int old_top = menu->top; + + if (menu->max <= menu->pagelen) /* less entries than lines */ { - menu->top = 0; - set_option (OPTNEEDREDRAW); - menu->redraw |= REDRAW_INDEX; + if (menu->top != 0) { + menu->top = 0; + set_option (OPTNEEDREDRAW); + } } - else if (menu->current >= menu->top + menu->pagelen) + else if (menu->current >= menu->top + menu->pagelen - c) /* indicator below bottom threshold */ { if (option (OPTMENUSCROLL) || (menu->pagelen <= 0)) - menu->top = menu->current - menu->pagelen + 1; + menu->top = menu->current - menu->pagelen + c + 1; else - menu->top += menu->pagelen * ((menu->current - menu->top) / menu->pagelen); - menu->redraw |= REDRAW_INDEX; + menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c; } - else if (menu->current < menu->top) + else if (menu->current < menu->top + c) /* indicator above top threshold */ { if (option (OPTMENUSCROLL) || (menu->pagelen <= 0)) - menu->top = menu->current; + menu->top = menu->current - c; else - { - menu->top -= menu->pagelen * ((menu->top + menu->pagelen - 1 - menu->current) / menu->pagelen); - if (menu->top < 0) - menu->top = 0; - } - menu->redraw |= REDRAW_INDEX; + menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) / (menu->pagelen - c)) - c; } + + /* make entries stick to bottom */ + menu->top = MIN (menu->top, menu->max - menu->pagelen); + menu->top = MAX (menu->top, 0); + + if (menu->top != old_top) + menu->redraw |= REDRAW_INDEX; } void menu_jump (MUTTMENU *menu) @@ -475,7 +484,9 @@ void menu_next_page (MUTTMENU *menu) void menu_prev_page (MUTTMENU *menu) { - if (menu->top > 0) + int c = MIN (MenuContext, menu->pagelen / 2); + + if (menu->top > c) { if ((menu->top -= menu->pagelen) < 0) menu->top = 0;