<<< Date Index >>>     <<< Thread Index >>>

Re: For 1.5.9: menu_move_off (was: Change in behavior <current-middle>)



Attachment: patch-1.5.9.tamo.menu_pageup.2
(more than pageup, though.)


On Fri, Mar 25, 2005 at 07:33:50PM +0100, Alain Bench wrote:
>  - <half-{up,down}> act broken: Do <first-entry> and move cursor down 34
> times with <next-entry> until you scroll 8 lines: You see 9-42 with
> cursor on #35. Do a <half-up>, you should see 1-34. But you see 8-41.
> Repeat <half-up> many times: You still see 8-41.
> 
>  - Amount of lines jumped by <half-{up,down}> is not constant 17, but
> random between 10 and 17 in my 34 lines 7 context example.

I made a new function to be used by both <next-page> and <half-down>,
and another one for both <prev-page> and <half-up>.
So, they will use the same algorithm.


>  - Probably we need a menu context for page jumps setting, with 0 lines
> as default. Or is it bloat? As a user my humble is 0 is fine: No setting
> needed. Others?

What do you mean?
If you type 41 when your screen is showing 9-42,
you expect to see the same screen (9-42) ?

Ignoring $menu_context is easy: see below.


>  - <{top,bottom}-page> trigger menu scrolling by $menu_context lines,
> which is surprising. Better ideas?

I made a new redraw-flag; REDRAW_IGNORE_CONTEXT.
<top-page> and <bottom-page> will use it to get rid of
the effect of $menu_context.


>  - When we add a new feature and an option to trigger it, the default
> should be the old behaviour, unless there is a huge benefit or security
> reason to do otherwise. New behaviour beeing just better, that's not
> enough to change default. Right? So probably $menu_move_off should be on
> by default.

Yeah, included in my patch.

-- 
tamo
--- ../mutt-1.5.9/init.h        2005-03-25 20:29:51.000000000 +0900
+++ ./init.h    2005-03-26 13:47:29.000000000 +0900
@@ -1096,7 +1096,7 @@
   ** This variable controls the number of lines of context that are given
   ** when scrolling through menus. (Similar to ``$$pager_context''.)
   */
-  { "menu_move_off",   DT_BOOL, R_NONE, OPTMENUMOVEOFF, 0 },
+  { "menu_move_off",   DT_BOOL, R_NONE, OPTMENUMOVEOFF, 1 },
   /*
   ** .pp
   ** When \fIunset\fP, the bottom entry of menus will never scroll up past
--- ../mutt-1.5.9/menu.c        2005-03-25 20:29:51.000000000 +0900
+++ ./menu.c    2005-03-26 13:45:58.000000000 +0900
@@ -386,14 +386,14 @@
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
       menu->top = menu->current - menu->pagelen + c + 1;
     else
-      menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / 
(menu->pagelen - c)) - c;
+      menu->top = menu->current - c;
   }
   else if (menu->current < menu->top + c) /* indicator above top threshold */
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
       menu->top = menu->current - c;
     else
-      menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - 
menu->current) / (menu->pagelen - c)) - c;
+      menu->top = menu->current - menu->pagelen + 1 + c;
   }
 
   if (!option (OPTMENUMOVEOFF)) /* make entries stick to bottom */
@@ -465,20 +465,37 @@
     mutt_error _("You cannot scroll up farther.");
 }
 
-void menu_next_page (MUTTMENU *menu)
+void menu_next_jump (MUTTMENU *menu, int jumplen)
 {
+  int c = MIN (MenuContext, menu->pagelen / 2);
+  int adj = 0;
+  /*
+   * ADJ is a number of lines menu->current moves later,
+   * i.e. how deep the cursor is above/below the threshold.
+   */
+  if (menu->current < menu->top + c)
+    adj = menu->top + c - menu->current;
+  else if (menu->current > menu->top + menu->pagelen - 1 - c)
+    adj = menu->top + menu->pagelen - 1 - c - menu->current;
+
   if (menu->max)
   {
     if (menu->top + menu->pagelen < menu->max)
     {
-      menu->top += menu->pagelen;
-      if (menu->current < menu->top)
-       menu->current = menu->top;
+      int oldtop = (menu->top += jumplen);
+      if (!option (OPTMENUMOVEOFF) && menu->top + menu->pagelen > menu->max)
+      {
+       menu->top = menu->max - menu->pagelen;
+       adj += (menu->top - oldtop);/* keep relative position - unnecessary? */
+      }
+      if (menu->current < menu->top + c)
+       menu->current += jumplen + adj;
+      menu->current = MIN (menu->current, menu->max - 1);
       menu->redraw = REDRAW_INDEX;
     }
     else if (menu->current != menu->max - 1 && !menu->dialog)
     {
-      menu->current = menu->max - 1;
+      menu->current = MIN (menu->current + jumplen, menu->max - 1);
       menu->redraw = REDRAW_MOTION;
     }
     else
@@ -488,34 +505,51 @@
     mutt_error _("No entries.");
 }
 
-void menu_prev_page (MUTTMENU *menu)
+void menu_next_page (MUTTMENU *menu)
+{
+  menu_next_jump (menu, menu->pagelen);
+}
+
+void menu_prev_jump (MUTTMENU *menu, int jumplen)
 {
   int c = MIN (MenuContext, menu->pagelen / 2);
+  int adj = 0;
+  if (menu->current < menu->top + c)
+    adj = menu->top + c - menu->current;
+  else if (menu->current > menu->top + menu->pagelen - 1 - c)
+    adj = menu->top + menu->pagelen - 1 - c - menu->current;
 
-  if (menu->top > c)
+  if (menu->top > 0)
   {
-    if ((menu->top -= menu->pagelen) < 0)
+    int oldtop = (menu->top -= jumplen);
+    if (oldtop < 0)
+    {
       menu->top = 0;
-    if (menu->current >= menu->top + menu->pagelen)
-      menu->current = menu->top + menu->pagelen - 1;
+      adj -= oldtop; /* keep relative position - unnecessary? */
+    }
+    if (menu->current > menu->top + menu->pagelen - 1 - c)
+      menu->current -= jumplen - adj;
+    menu->current = MAX (menu->current, 0);
     menu->redraw = REDRAW_INDEX;
   }
   else if (menu->current && !menu->dialog)
   {
-    menu->current = 0;
+    menu->current = MAX (menu->current - jumplen, 0);
     menu->redraw = REDRAW_MOTION;
   }
   else
     mutt_error _("You are on the first page.");
 }
 
+void menu_prev_page (MUTTMENU *menu)
+{
+  menu_prev_jump (menu, menu->pagelen);
+}
+
 void menu_top_page (MUTTMENU *menu)
 {
-  if (menu->current != menu->top)
-  {
-    menu->current = menu->top;
-    menu->redraw = REDRAW_MOTION;
-  }
+  menu->current = menu->top;
+  menu->redraw = REDRAW_MOTION | REDRAW_IGNORE_CONTEXT;
 }
 
 void menu_bottom_page (MUTTMENU *menu)
@@ -525,7 +559,7 @@
     menu->current = menu->top + menu->pagelen - 1;
     if (menu->current > menu->max - 1)
       menu->current = menu->max - 1;
-    menu->redraw = REDRAW_MOTION;
+    menu->redraw = REDRAW_MOTION | REDRAW_IGNORE_CONTEXT;
   }
   else
     mutt_error _("No entries.");
@@ -571,44 +605,12 @@
 
 void menu_half_up (MUTTMENU *menu)
 {
-  if (menu->top > 0)
-  {
-    if ((menu->top -= menu->pagelen / 2) < 0)
-      menu->top = 0;
-    if (menu->current >= menu->top + menu->pagelen)
-      menu->current = menu->top + menu->pagelen - 1;
-    menu->redraw = REDRAW_INDEX;
-  }
-  else if (menu->current && !menu->dialog)
-  {
-    menu->current = 0;
-    menu->redraw = REDRAW_MOTION;
-  }
-  else
-    mutt_error _("First entry is shown.");
+  menu_prev_jump (menu, menu->pagelen / 2);
 }
 
 void menu_half_down (MUTTMENU *menu)
 {
-  if (menu->max)
-  {
-    if (menu->top + menu->pagelen < menu->max)
-    {
-      menu->top += menu->pagelen / 2;
-      if (menu->current < menu->top)
-       menu->current = menu->top;
-      menu->redraw = REDRAW_INDEX;
-    }
-    else if (menu->current != menu->max - 1 && !menu->dialog)
-    {
-      menu->current = menu->max - 1;
-      menu->redraw = REDRAW_INDEX;
-    }
-    else
-      mutt_error _("Last entry is shown.");
-  }
-  else
-    mutt_error _("No entries.");
+  menu_next_jump (menu, menu->pagelen / 2);
 }
 
 void menu_current_top (MUTTMENU *menu)
@@ -826,7 +828,7 @@
     return (OP_REDRAW);
   }
   
-  if (!menu->dialog)
+  if (!menu->dialog && !(menu->redraw & REDRAW_IGNORE_CONTEXT))
     menu_check_recenter (menu);
   
   if (menu->redraw & REDRAW_STATUS)
--- ../mutt-1.5.9/mutt_menu.h   2003-10-05 04:29:27.000000000 +0900
+++ ./mutt_menu.h       2005-03-26 12:42:42.000000000 +0900
@@ -31,6 +31,7 @@
 #define REDRAW_FULL            (1<<5)
 #define REDRAW_BODY            (1<<6)
 #define REDRAW_SIGWINCH                (1<<7)
+#define REDRAW_IGNORE_CONTEXT  (1<<8)
 
 #define M_MODEFMT "-- Mutt: %s"