]> granicus.if.org Git - neomutt/commitdiff
Christoph Berg's menu_context, and a version of menu_move_off where
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 12 Feb 2005 20:08:19 +0000 (20:08 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 12 Feb 2005 20:08:19 +0000 (20:08 +0000)
that's not optional, but where mutt will just try to avoid moving
off the bottom.  Complain to mutt-dev if you want this to be
optional.

globals.h
init.h
menu.c

index f2fada84b40c71e71ec9c14f1aa30d6ed2dd8b4f..03c7d241fee0f50b2b08f35e7c46a5a41cb4d909 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -165,6 +165,7 @@ WHERE unsigned short Counter INITVAL (0);
 
 WHERE short ConnectTimeout;
 WHERE short HistSize;
+WHERE short MenuContext;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
diff --git a/init.h b/init.h
index 6b899633cb6ca0a2e05ccce671a78f05fa76831d..b1088e330a0e30fb7b91265175e9d497d723d948 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1090,6 +1090,12 @@ struct option_t MuttVars[] = {
   ** If unset, Mutt will remove your address (see the ``alternates''
   ** command) from the list of recipients when replying to a message.
   */
+  { "menu_context",    DT_NUM,  R_NONE, UL &MenuContext, 0 },
+  /*
+  ** .pp
+  ** This variable controls the number of lines of context that are given
+  ** when scrolling through menus. (Similar to ``$$pager_context''.)
+  */
   { "menu_scroll",     DT_BOOL, R_NONE, OPTMENUSCROLL, 0 },
   /*
   ** .pp
diff --git a/menu.c b/menu.c
index e022a12c2b12c13a034af419e7582fa2bd57b559..18e00d624ffb1bc2667d56fca465f57d100b7569 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -371,32 +371,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)
@@ -480,7 +485,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;