Re: For 1.5.9: menu_move_off (was: Change in behavior <current-middle>)
On Mon, 28 Mar 2005, Alain Bench wrote:
> On Saturday, March 26, 2005 at 4:14:12 PM +0900, Tamotsu Takahashi wrote:
>
> > 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.
>
> Fine, much thanks! :-)
>
> Unfortunately cursor positioning changed. Let's say you see 4-37
> cursor on 30, then <previous-page>: You should see 1-34 cursor on 1. But
> you see 1-34 cursor on 27, and have to <previous-page> again to set
> cursor on 1.
That was my mistake. The previous patch had my comment:
/* keep relative position - unnecessary? */
Fixed in v3 (attached).
> There are also small illogical effects in middle index, but
> difficult to put in words: What I called "fixed altitude" still works,
> but not always.
Please let me know if v3 has this bug.
> > On Fri, Mar 25, 2005 at 07:33:50PM +0100, Alain Bench wrote:
> >> we need a menu context for page jumps setting, with 0 lines as
> >> default. Or is it bloat?
> > What do you mean?
>
> That would be with $menu_page_context=1 say 1-34 + <next-page> =
> 34-67, with 1 common line of context between old and new page. This can
> ease user following jumps. Probably choices can be only 0 or 1 line, and
> <half-{up,down}> don't need it (only for <{previous,next}-page>).
>
> The more I think to it the more I feel it would be usefull.
Very easy to implement.
V3 has $menu_jump_context.
> I was probably more thinking to limit cursor position to top +
> $menu_context or bottom - $menu_context. 50-83 cursor on 70, then
> <top-page>, would give 50-83 cursor on 57. But this also is a bad idea,
> especially with huge $menu_context.
>
> No: Let's say current behaviour is not *so* bad, please forget this
> bullet was written.
Reverted.
--
tamo
diff --exclude='*~' -u ../mutt/globals.h ./globals.h
--- ../mutt/globals.h 2005-02-13 14:14:49.000000000 +0900
+++ ./globals.h 2005-03-28 22:13:23.011619336 +0900
@@ -166,6 +166,7 @@
WHERE short ConnectTimeout;
WHERE short HistSize;
WHERE short MenuContext;
+WHERE short MenuJumpContext;
WHERE short PagerContext;
WHERE short PagerIndexLines;
WHERE short ReadInc;
diff --exclude='*~' -u ../mutt/init.h ./init.h
--- ../mutt/init.h 2005-03-23 22:29:37.000000000 +0900
+++ ./init.h 2005-03-28 22:32:58.577440712 +0900
@@ -1103,7 +1103,15 @@
** 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_jump_context", DT_NUM, R_NONE, UL &MenuJumpContext, 0 },
+ /*
+ ** .pp
+ ** In menus, the next-page and prev-page functions usually jumps exactly
+ ** how many menu items your screen shows. $$$menu_jump_context decreases the
+ ** length of jumps. When this is set to 1, the last entry will be the first
+ ** entry of the next page.
+ */
+ { "menu_move_off", DT_BOOL, R_NONE, OPTMENUMOVEOFF, 1 },
/*
** .pp
** When \fIunset\fP, the bottom entry of menus will never scroll up past
diff --exclude='*~' -u ../mutt/menu.c ./menu.c
--- ../mutt/menu.c 2005-03-18 18:15:57.000000000 +0900
+++ ./menu.c 2005-03-28 22:15:38.700991416 +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,30 @@
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;
+ 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;
+ menu->top += jumplen;
+ if (!option (OPTMENUMOVEOFF) && menu->top + menu->pagelen > menu->max)
+ menu->top = menu->max - menu->pagelen;
+ 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,27 +498,43 @@
mutt_error _("No entries.");
}
-void menu_prev_page (MUTTMENU *menu)
+void menu_next_page (MUTTMENU *menu)
+{
+ menu_next_jump (menu, menu->pagelen - MenuJumpContext);
+}
+
+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)
+ if ((menu->top -= jumplen) < 0);
menu->top = 0;
- if (menu->current >= menu->top + menu->pagelen)
- menu->current = menu->top + menu->pagelen - 1;
+ 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 - MenuJumpContext);
+}
+
void menu_top_page (MUTTMENU *menu)
{
if (menu->current != menu->top)
@@ -571,44 +597,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)