Re: mutt/2019: menu_context itches (Re: your mail)
* Mon Aug 1 2005 ossi@xxxxxxx <ossi@xxxxxxx>
> >Description:
> when the cursor is outside of the area menu_context is supposed to keep it in
> (this happens quite often when exiting from some sub-view), one is often
> faced with unexpected scrolls. "correct position by one line" seems to be
> applied blindly regardless of the preceding operation. e.g., moving the
> cursor in the direction of the "allowed region" should not scroll. anyway,
> the simplest and in many/all cases correct fix would be just re-adjusting the
> position when returning to a menu.
What about my patch for menu_context?
http://marc.theaimsgroup.com/?l=mutt-dev&m=111711676317904&w=2
(Note: $menu_context will be renamed to $menu_indicator_margin by
this patch (by AB). Also, $menu_move_off to $menu_move (by TG).)
I suppose this patch fixes it with these changes:
===========================================================
- menu->top += (menu->pagelen - c) * ((menu->current - menu->top) /
(menu->pagelen - c)) - c;
+ menu->top = menu->current - c;
===========================================================
and
===========================================================
- menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 -
menu->current) / (menu->pagelen - c)) - c;
+ menu->top = menu->current - (menu->pagelen - 1) + c;
===========================================================
--
tamo
? patch-1.5.9.ab+tg+tamo.menu.1
Index: PATCHES
===================================================================
RCS file: /home/roessler/cvs/mutt/PATCHES,v
retrieving revision 3.6
diff -p -u -r3.6 PATCHES
--- PATCHES 9 Dec 2002 17:44:54 -0000 3.6
+++ PATCHES 2 Aug 2005 08:26:37 -0000
@@ -0,0 +1,2 @@
+patch-1.5.9.ab.menu_page_context_and_cursor_margin_proposed_renaming.1
+and menu_move
Index: globals.h
===================================================================
RCS file: /home/roessler/cvs/mutt/globals.h,v
retrieving revision 3.19
diff -p -u -r3.19 globals.h
--- globals.h 1 Aug 2005 07:35:04 -0000 3.19
+++ globals.h 2 Aug 2005 08:26:38 -0000
@@ -169,6 +169,7 @@ WHERE unsigned short Counter INITVAL (0)
WHERE short ConnectTimeout;
WHERE short HistSize;
WHERE short MenuContext;
+WHERE short MenuIndicatorMargin;
WHERE short PagerContext;
WHERE short PagerIndexLines;
WHERE short ReadInc;
Index: init.h
===================================================================
RCS file: /home/roessler/cvs/mutt/init.h,v
retrieving revision 3.75
diff -p -u -r3.75 init.h
--- init.h 26 Jul 2005 16:40:16 -0000 3.75
+++ init.h 2 Aug 2005 08:26:40 -0000
@@ -1135,15 +1135,25 @@ struct option_t MuttVars[] = {
{ "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''.)
+ ** In menus (eg. index), the number of lines PageUp or PageDown jumps is
+ ** usually the same as the number of menu-items your screen shows. If you
+ ** set $$$menu_context to a non-zero number, PageUp or PageDown
+ ** will jump less. For example, the value "1" will let PageDown keep the
+ ** last item of the previous screen as the first item on the next screen.
+ ** Identical to ``$$pager_context'' for the internal pager.
+ */
+ { "menu_indicator_margin", DT_NUM, R_NONE, UL &MenuIndicatorMargin, 0 },
+ /*
+ ** .pp
+ ** This variable controls the number of lines of context that are shown
+ ** around indicator when scrolling through menus.
*/
- { "menu_move_off", DT_BOOL, R_NONE, OPTMENUMOVEOFF, 1 },
+ { "menu_move", DT_BOOL, R_NONE, OPTMENUMOVE, 0 },
/*
** .pp
- ** When \fIunset\fP, the bottom entry of menus will never scroll up past
+ ** When \fIset\fP, the bottom entry of menus will never scroll up past
** the bottom of the screen, unless there are less entries than lines.
- ** When \fIset\fP, the bottom entry may move off the bottom.
+ ** When \fIunset\fP, the bottom entry may move off the bottom.
*/
{ "menu_scroll", DT_BOOL, R_NONE, OPTMENUSCROLL, 0 },
/*
@@ -1287,6 +1297,8 @@ struct option_t MuttVars[] = {
** when displaying the next or previous page in the internal pager. By
** default, Mutt will display the line after the last one on the screen
** at the top of the next page (0 lines of context).
+ ** Identical to ``$$menu_context'' for the messages index, folder
+ ** browser, and other menus.
*/
{ "pager_format", DT_STR, R_PAGER, UL &PagerFmt, UL "-%Z- %C/%m:
%-20.20n %s" },
/*
Index: menu.c
===================================================================
RCS file: /home/roessler/cvs/mutt/menu.c,v
retrieving revision 3.18
diff -p -u -r3.18 menu.c
--- menu.c 12 Jun 2005 18:28:29 -0000 3.18
+++ menu.c 2 Aug 2005 08:26:41 -0000
@@ -374,32 +374,32 @@ void menu_redraw_prompt (MUTTMENU *menu)
void menu_check_recenter (MUTTMENU *menu)
{
- int c = MIN (MenuContext, menu->pagelen / 2);
+ int c = MIN (MenuIndicatorMargin, menu->pagelen / 2);
int old_top = menu->top;
- if (!option (OPTMENUMOVEOFF) && menu->max <= menu->pagelen) /* less entries
than lines */
+ if (option (OPTMENUMOVE) && menu->max <= menu->pagelen) /* less entries than
lines */
{
if (menu->top != 0) {
menu->top = 0;
set_option (OPTNEEDREDRAW);
}
}
- else if (menu->current >= menu->top + menu->pagelen - c) /* indicator below
bottom threshold */
+ else if (menu->current > menu->top + (menu->pagelen - 1) - c) /* indicator
below bottom threshold */
{
if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
- menu->top = menu->current - menu->pagelen + c + 1;
+ menu->top = menu->current - (menu->pagelen - 1) + c;
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 */
+ if (option (OPTMENUMOVE)) /* make entries stick to bottom */
menu->top = MIN (menu->top, menu->max - menu->pagelen);
menu->top = MAX (menu->top, 0);
@@ -436,10 +436,10 @@ void menu_next_line (MUTTMENU *menu)
{
if (menu->max)
{
- int c = MIN (MenuContext, menu->pagelen / 2);
+ int c = MIN (MenuIndicatorMargin, menu->pagelen / 2);
if (menu->top + 1 < menu->max - c
- && (option(OPTMENUMOVEOFF) || (menu->max > menu->pagelen && menu->top <
menu->max - menu->pagelen)))
+ && ((! option(OPTMENUMOVE)) || (menu->max > menu->pagelen && menu->top <
menu->max - menu->pagelen)))
{
menu->top++;
if (menu->current < menu->top + c && menu->current < menu->max - 1)
@@ -457,7 +457,7 @@ void menu_prev_line (MUTTMENU *menu)
{
if (menu->top > 0)
{
- int c = MIN (MenuContext, menu->pagelen / 2);
+ int c = MIN (MenuIndicatorMargin, menu->pagelen / 2);
menu->top--;
if (menu->current >= menu->top + menu->pagelen - c && menu->current > 1)
@@ -468,48 +468,75 @@ void menu_prev_line (MUTTMENU *menu)
mutt_error _("You cannot scroll up farther.");
}
-void menu_next_page (MUTTMENU *menu)
-{
+/*
+ * pageup: jumplen == -pagelen
+ * pagedown: jumplen == pagelen
+ * halfup: jumplen == -pagelen/2
+ * halfdown: jumplen == pagelen/2
+ */
+#define DIRECTION ((neg * 2) + 1)
+void menu_length_jump (MUTTMENU *menu, int jumplen)
+{
+ int tmp, neg = (jumplen >= 0) ? 0 : -1;
+ int c = MIN (MenuIndicatorMargin, menu->pagelen / 2);
+
if (menu->max)
{
- if (menu->top + menu->pagelen < menu->max)
- {
- menu->top += menu->pagelen;
- if (menu->current < menu->top)
- menu->current = menu->top;
+ /* possible to scroll? */
+ if (DIRECTION * menu->top <
+ (tmp = (neg ? 0 : menu->max /* -1 */ - menu->pagelen /* -1 */)))
+ {
+ menu->top += jumplen;
+
+ /* jumped too long? */
+ if ((neg || option (OPTMENUMOVE)) &&
+ DIRECTION * menu->top > tmp)
+ menu->top = tmp;
+
+ /* need to move the cursor? */
+ if ((DIRECTION *
+ (tmp = (menu->current -
+ (menu->top + (neg ? (menu->pagelen - 1) - c : c))
+ ))) < 0)
+ menu->current -= tmp;
+
menu->redraw = REDRAW_INDEX;
}
- else if (menu->current != menu->max - 1 && !menu->dialog)
+ else if (menu->current != (neg ? 0 : menu->max - 1) && !menu->dialog)
{
- menu->current = menu->max - 1;
+ menu->current += jumplen;
menu->redraw = REDRAW_MOTION;
}
else
- mutt_error _("You are on the last page.");
+ mutt_error (neg ? _("You are on the first page.")
+ : _("You are on the last page."));
+
+ menu->current = MIN (menu->current, menu->max - 1);
+ menu->current = MAX (menu->current, 0);
}
else
mutt_error _("No entries.");
}
+#undef DIRECTION
+
+void menu_next_page (MUTTMENU *menu)
+{
+ menu_length_jump (menu, MAX (menu->pagelen - MenuContext, 0));
+}
void menu_prev_page (MUTTMENU *menu)
{
- int c = MIN (MenuContext, menu->pagelen / 2);
+ menu_length_jump (menu, 0 - MAX (menu->pagelen - MenuContext, 0));
+}
- if (menu->top > c)
- {
- if ((menu->top -= menu->pagelen) < 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 _("You are on the first page.");
+void menu_half_down (MUTTMENU *menu)
+{
+ menu_length_jump (menu, menu->pagelen / 2);
+}
+
+void menu_half_up (MUTTMENU *menu)
+{
+ menu_length_jump (menu, 0 - menu->pagelen / 2);
}
void menu_top_page (MUTTMENU *menu)
@@ -572,48 +599,6 @@ void menu_last_entry (MUTTMENU *menu)
mutt_error _("No entries.");
}
-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.");
-}
-
-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.");
-}
-
void menu_current_top (MUTTMENU *menu)
{
if (menu->max)
Index: mutt.h
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt.h,v
retrieving revision 3.45
diff -p -u -r3.45 mutt.h
--- mutt.h 1 Aug 2005 07:35:04 -0000 3.45
+++ mutt.h 2 Aug 2005 08:26:41 -0000
@@ -394,7 +394,7 @@ enum
OPTMARKERS,
OPTMARKOLD,
OPTMENUSCROLL, /* scroll menu instead of implicit next-page */
- OPTMENUMOVEOFF, /* allow menu to scroll past last entry */
+ OPTMENUMOVE, /* allow menu to scroll past last entry */
OPTMETAKEY, /* interpret ALT-x as ESC-x */
OPTMETOO,
OPTMHPURGE,